TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajesh Sut
NA
3
1.6k
Calling a function from repository to controller in asp.net
Mar 7 2018 1:18 PM
Hello everybody, I'm currently an intern, developing a company's own product, my current task is to build a part of website for managing users, It's basically an angular crud app with asp.net backend. Backend is written primarily for android and ios versions of app, so I'm building an api using parts of that backend for my task...
So here's the deal, let me give you an example of what I'm trying to ask, because I'm not too good with the asp.net framework yet...
In my UserController I'm going to set get, post, patch and delete methods by getting for example
GetAllUsersByOrganization from UserBussinessObject..
[Route(
"{id}/users"
), HttpGet]
public
IHttpActionResult GetUsers(
int
id)
{ var result = UserBusinessObject.GetAllUsersByOrganization(id);
return
Ok(
new
{ data = result });
}
But here's the deal, if I have in UserBussinessObject a function like this
/// Update user by organization manager
/// </summary>
/// <param name="userUpdateModel"></param>
/// <returns></returns>
[LogException]
public
int
UpdateUserByManager([Required]User userUpdateModel, User currentuser)
{
// Find user to update User
userToUpdate = UserRepository.GetUserById(userUpdateModel.UserId);
if
(userToUpdate !=
null
)
{
// Update user in database
UserRepository.UpdateUser(userToUpdate);
return
(
int
)DBStatusEnum.Success;
}
else
{
return
(
int
)DBStatusEnum.NoResult;
}
}
with UserRepository that has UpdateUser
as
[LogException]
public
int
UpdateUser([Required]User user)
{var parameters = ConstructParamsForEntity(user,
"Password"
,
"CreateDate"
,
"UserInfoId"
,
"Activated"
,
"Role"
,
"ProfileImage"
,
"SelectedLocations"
).ToList();
if
(user.Password !=
null
)
{
var parameter =
new
SqlParameter(
"PasswordHash"
, PasswordManager.GetHashString(user.Password));
parameters.Add(parameter);
}
ExecuteNonQuery(GlobalConstants.SP_USER_UPDATE, CommandType.StoredProcedure, parameters.ToArray());
return
(
int
)DBStatusEnum.Success;
}
How can I create patch method in my UserController, I'm not that experienced and not sure how to call it from UserBussinessObject that gets it from UserRepository.cs
Here's my patch method so far, so If you get my problem, please help..
[Route(
"user/{id}"
), HttpPatch]
public
IHttpActionResult EditUser(User userUpdate, User user)
{var userToUpdate = UserBusinessObject.GetUserById(userUpdate.UserId);
//returns user from user repository?
//if Id is not found, return
if
(userToUpdate ==
null
)
{
return
BadRequest(
"User not found"
);}
else
return
Ok();
///call from UserRepository.cs UpdateUser than pass userToUpdate ?
}
Thanks a lot, hopefully you'll understand
Reply
Answers (
1
)
Microsoft certification
Classification Html Table in ASP.net MVC