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
-
-
-
-
- [LogException]
- public int UpdateUserByManager([Required]User userUpdateModel, User currentuser)
- {
-
- userToUpdate = UserRepository.GetUserById(userUpdateModel.UserId);
- if (userToUpdate != null)
- {
- 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);
-
-
- if (userToUpdate == null)
- { return BadRequest("User not found");}
- else return Ok();
-
- }
Thanks a lot, hopefully you'll understand