public override HttpResponseMessage PutEntity(UserDTO userDTO) { var isDuplicateUserName = _userService.IsDuplicateUserName(userDTO.UserName, userDTO.Id); if (isDuplicateUserName) { ModelState.AddModelHandledError("UserName", "نام کاربری تکراری می باشد"); } if (userDTO.Password != userDTO.ConfirmPassword) { ModelState.AddModelHandledError("ConfirmPassword", "کلمه عبور صحیح نمی باشد"); } if (ModelState.IsValid) { var user = userDTO.GetModel(); user.UserProfile = new UserProfile { Password = userDTO.ComparePassword != userDTO.Password ? _userService.GetMd5Hash(userDTO.Password) : userDTO.Password, UserName = userDTO.UserName }; var updatedUserId = _userService.Update(user); return(Request.CreateResponse(HttpStatusCode.OK, new { Data = new[] { userDTO }, Total = 1 })); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); }
public override HttpResponseMessage PostEntity([System.Web.Http.ModelBinding.ModelBinder(typeof(Core.Mvc.ModelBinders.DataSourceRequestModelBinder))] DataSourceRequest request, CompanyViewModel viewModel) { if (!string.IsNullOrEmpty(viewModel.CompanyNationalCode)) { if (!viewModel.CompanyIsValidNationalCode) { ModelState.AddModelHandledError("CompanyNationalCode", "کد ملی معتبر راوارد نمائید"); } } var isDuplicateName = _companyService.Filter(a => a.Name == viewModel.CompanyName).Any(); if (isDuplicateName) { ModelState.AddModelHandledError("DomainName", "نام تکراری می باشد"); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); } var savedDomainName = _companyService.Create(viewModel.Model); viewModel.SetModel(savedDomainName); var response = Request.CreateResponse(HttpStatusCode.Created, new { Data = new[] { viewModel }, Total = 1 }); return(response); }
public override HttpResponseMessage PostEntity( [System.Web.Http.ModelBinding.ModelBinder(typeof(Core.Mvc.ModelBinders.DataSourceRequestModelBinder))] DataSourceRequest request, UserViewModel userViewModel) { var isDuplicateUserName = _userService.IsDuplicateUserName(userViewModel.UserName, userViewModel.Id); if (isDuplicateUserName) { ModelState.AddModelHandledError("UserName", "نام کاربری تکراری می باشد"); } if (userViewModel.Password != userViewModel.ConfirmPassword) { ModelState.AddModelHandledError("ConfirmPassword", "کلمه عبور صحیح نمی باشد"); } if (ModelState.IsValid) { var roleid = userViewModel.RoleIdForHead; var foundedCompanyRole = _companyRoleService.Filter(a => a.RoleId == roleid).FirstOrDefault(); var foundedCompany = _companyService.Find(foundedCompanyRole.CompanyId); var user = userViewModel.GetModel(); //چون کاربر ادمین هر سازمان توسط ما تعریف می شود پس باید سازمان آن را هم مشخص کنیم user.CurrentCompanyId = foundedCompany.Id; user.UserProfile = new UserProfile { Password = _userService.GetMd5Hash(userViewModel.Password), UserName = userViewModel.UserName, // CurrentCompanyId = foundedCompany.Id }; user.UserRoles = AddRoleToUser(userViewModel, foundedCompany.Id); var addedUser = _userService.Create(user); userViewModel.SetModel(addedUser); return(Request.CreateResponse(HttpStatusCode.Created, new { Data = new[] { userViewModel }, Total = 1 })); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); }
///ایجاد نقش public override HttpResponseMessage PostEntity(RoleDTO roleDTO) { var isRoleNameDuplicate = _roleService .Filter(a => a.Name == roleDTO.Name) .Any(); if (isRoleNameDuplicate) { ModelState.AddModelHandledError("Name", "عنوان نقش تکراری می باشد"); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); } var insertedRole = _roleService.Create(roleDTO.Model); roleDTO.SetModel(insertedRole); var response = Request.CreateResponse(HttpStatusCode.Created, new { Data = new[] { roleDTO } }); return(response); }
public override HttpResponseMessage DeleteEntity(RoleDTO roleDTO) { if (ModelState.IsValid) { var role = _roleService.Find(roleDTO.Id); try { _roleService.Delete(role); } catch { //MessageStrore.Add(new Message { text = "dd", type = MessageType.error }); //return Request.CreateErrorResponse(HttpStatusCode.NotFound,ex); ModelState.AddModelHandledError("Name", "این رکورد مورد استفاده است"); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); } return(Request.CreateResponse(HttpStatusCode.OK, new { Data = new[] { roleDTO } })); } return(Request.CreateResponse("ValidationError.")); }
public override HttpResponseMessage PostEntity(UserRoleDTO userRoleDTO) { var hasDuplicateRole = _userRoleService .HasDuplicateRoleAssigne(userRoleDTO.RoleId, userRoleDTO.UserId); if (hasDuplicateRole) { ModelState.AddModelHandledError("RoleId", "نقش انتخاب شده تکراری است"); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); } var model = userRoleDTO.GetModel(); var userRole = _userRoleService.Create(model); userRoleDTO.SetModel(userRole); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, new { Data = new[] { userRoleDTO } }); return(response); }
public override HttpResponseMessage PostEntity(UserDTO userDTO) { var isDuplicateUserName = _userService.IsDuplicateUserName(userDTO.UserName, userDTO.Id); if (isDuplicateUserName) { ModelState.AddModelHandledError("UserName", "نام کاربری تکراری می باشد"); } if (userDTO.Password != userDTO.ConfirmPassword) { ModelState.AddModelHandledError("ConfirmPassword", "کلمه عبور صحیح نمی باشد"); } if (ModelState.IsValid) { var user = userDTO.Model; // user.CurrentCompanyId = _userService.AppBase.CompanyId; user.UserProfile = new UserProfile { Password = _userService.GetMd5Hash(userDTO.Password), UserName = userDTO.UserName, // CurrentCompanyId = _userService.AppBase.CompanyId }; var addedUser = _userService.Create(user); userDTO.SetModel(addedUser); //userDTO.UserName = userDTO.UserName; return(Request.CreateResponse(HttpStatusCode.Created, new { Data = new[] { userDTO } })); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState)); }