public AccountController(AccountService accountService, User user, EditAccountModel editAccountModel, DoctorService doctorService) { _accountService = accountService; _user = user; _doctorService = doctorService; _editAccountModel = editAccountModel; }
public void EditAccountProps(Guid userId, EditAccountModel editRequest) { lock (Locker) { try { var targetAccState = accountStates.FirstOrDefault(state => state.ComplexAccount.Id == userId); if (targetAccState == null) { throw new InvalidOperationException($"Account '{ userId }' state not found in cache"); } EditSimpleProperties(editRequest, targetAccState.ComplexAccount); AccountDbInteracter.Instance.AddOrUpdate(targetAccState.ComplexAccount); ImageService.Instance.SaveUserAvatar(targetAccState.ComplexAccount.Id, editRequest.NewImageBlob); Task.Run(() => informerService.NotifyAllFriendsAboutUser(targetAccState)); } catch (Exception ex) { ex.Message.WriteToConsole(ConsoleColor.Red); } } }
public ViewModelLocator() { _main = new MainViewModel(); _transActionList = _main._TransactionListModel; _editTransactionModel = _main._EditTransactionModel; _chartModel = _main._ChartModel; _editAccountModel = _main._EditAccountModel; }
public IHttpActionResult Update(EditAccountModel model) { IHttpActionResult httpActionResult; var userManager = new ApplicationUserManager(new UserStore <Account>(this.db)); Account account = userManager.Users.FirstOrDefault(x => x.Id == model.Id); if (account == null) { error.Add("Not Found"); httpActionResult = new ErrorActionResult(Request, HttpStatusCode.NotFound, error); } if (string.IsNullOrEmpty(model.username)) { error.Add("User Name is required"); httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } if (string.IsNullOrEmpty(model.fullName)) { error.Add("Full Name is required"); httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } if (string.IsNullOrEmpty(model.email)) { error.Add("Email is required"); httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } if (!CheckPhoneNumber.CheckCorrectPhoneNumber(model.phoneNumber)) { error.Add("Phone number is not correct!"); httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } if (error.errors.Count != 0) { httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } else { account.UserName = model.username ?? model.username; account.FullName = model.fullName ?? model.fullName; account.Email = model.email ?? model.email; account.PhoneNumber = model.phoneNumber ?? model.phoneNumber; account.Status = model.Status; if (!string.IsNullOrEmpty(model.password)) { userManager.RemovePassword(model.Id); userManager.AddPassword(model.Id, model.password); } else { error.Add("Password is required!"); httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } db.Entry(account).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); httpActionResult = Ok(new AccountModel(account)); } return(httpActionResult); }
public void Edit(EditAccountModel model) { Account entity = _db.Table.Find <Account>(model.Id); entity = model.MapTo <Account>(entity); entity.LastUpdateDate = DateTime.Now; entity.CheckCanViewStore(); _db.Update(entity); _db.SaveChange(); }
public IActionResult Edit(EditAccountModel model) { User user = new User() { Id = model.Id, Username = model.Username, Birthday = model.Birthday }; _accountLogic.UpdateUser(user); return(RedirectToAction("Account", "Account")); }
public EditAccountViewModel(EditAccountModel model, IPleaseWaitService pleaseWaitService, IMessageService messageService) { EditAccount = model; _messageService = messageService; _pleaseWaitService = pleaseWaitService; SaveAccountCommand = new Command(SaveAccount); DeleteAccountCommand = new Command(DeleteAccount); }
public IActionResult Edit(int id) { EditAccountModel model = new EditAccountModel(); User user = _accountLogic.GetUser(id); model.Id = id; model.Username = user.Username; model.Birthday = user.Birthday; return(View(model)); }
public ActionResult Edit(int id) { var result = _db.UserProfiles.First(x => x.UserId == id); var model = new EditAccountModel(); model.UserId = id; model.UserName = result.UserName; model.RoleId = result.webpages_Roles.FirstOrDefault()?.RoleId ?? 2; return(View(model)); }
public ActionResult EditAccount(EditAccountModel model) { EventLogHandler Logger = new EventLogHandler(); var sessionUser = Session["Username"] as string; if (ModelState.IsValid) { List <ChartOfAcc> accountsList; List <string> AccountDetails = new List <string>(); List <string> NewAccountDetails = new List <string>(); using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString())) { accountsList = db.Query <ChartOfAcc>($"Select * From dbo.ChartOfAccounts Where AccountNumber = @ID", new { ID = model.AccountNumber }).ToList(); } AccountDetails.Add("Name:" + accountsList[0].AccountName); AccountDetails.Add("Active: " + accountsList[0].Active); AccountDetails.Add("Type: " + accountsList[0].AccountType); AccountDetails.Add("Description:" + accountsList[0].AccountDescription); string DetailedFrom = String.Join("|^|", AccountDetails); using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString())) { string sql = "Update dbo.ChartOfAccounts set AccountName = @AccountName, " + "AccountType = @AccountType, AccountDescription = @AccountDescription," + "Active = @Active Where AccountNumber = @AccountNumber"; db.Execute(sql, new { AccountNumber = model.AccountNumber, AccountName = model.AccountName, AccountType = model.AccountType, AccountDescription = model.AccountDescription, Active = model.Active }); } NewAccountDetails.Add("Name:" + model.AccountName); NewAccountDetails.Add("Active: " + model.Active); NewAccountDetails.Add("Type: " + model.AccountType); NewAccountDetails.Add("Description:" + model.AccountDescription); string DetailedTo = String.Join("|^|", NewAccountDetails); TempData["Message"] = "Your entry was successfully updated!"; Logger.LogAdminEditAccount(sessionUser, model.AccountName, DetailedFrom, DetailedTo); return(RedirectToAction("ChartOfAccounts")); } return(View(model)); }
public async Task <bool> UpdateAccount(Guid id, EditAccountModel model, CancellationToken token = default) { var account = model.MapToAccount(id, _scopeControl.GetUserId()); if (account.IsInValid()) { _scopeControl.AddNotifications(account.Notifications); return(false); } _repository.Update(account); return(await _repository.UnitOfWork.Commit(token)); }
public IActionResult SaveAccount(EditAccountModel model) { var account = AccountService.GetLogonAccount(); account.Name = model.AccountName; account.NativeLanguageID = model.NativeLanguageID.ToNullable(); account.LearningLanguageID = model.LearningLanguageID.ToNullable(); account.AdditionalLanguageID = model.AdditionalLanguageID.ToNullable(); AccountService.Update(account); return(RedirectToAction("Index")); }
public IActionResult Edit() { var account = AccountService.GetLogonAccount(); var model = new EditAccountModel() { AvailableLanguages = LanguagesService.GetAll().ToArray(), AccountName = account.Name, NativeLanguageID = account.NativeLanguageID ?? 0, LearningLanguageID = account.LearningLanguageID ?? 0, AdditionalLanguageID = account.AdditionalLanguageID ?? 0, }; return(View(model)); }
public ActionResult Edit() { //Automatically pulls user's existing data. If null, the textbox is blank //This calls functions from the RetrievalProcessor class in the DatabaseBusinessLogic folder EditAccountModel data = new EditAccountModel { FirstName = RetrieveName(), LastName = RetrieveLastName(), Email = RetrieveEmail(), Phone = RetrievePhone(), NotificationSchedule = (Notification)RetrieveNotification() }; return(View(data)); }
public async Task <IActionResult> EditAccount(long accountId, [FromBody] EditAccountModel model) { try { model.Id = accountId; var result = await accountLib.EditAccountAsync(model, CurrentUserId); return(CustomResult(result)); } catch (System.Exception exp) { return(CustomError(exp)); } }
public ActionResult EditPost(EditAccountModel model) { if (ModelState.IsValid) { MembershipUser user = Membership.GetUser(); if (model.Email != null) { user.Email = model.Email; } if (model.Image != null) { Profile.SetPropertyValue("AvatarUrl", model.Image); Profile.Save(); } } return(View("Edit", model)); }
public IActionResult EditAccount(EditAccountModel model, string id) { ViewBag.IsLogin = !string.IsNullOrEmpty(cache.GetString("user")); if (ViewBag.IsLogin) { ViewBag.User = JsonConvert.DeserializeObject <AccountModel>(cache.GetString("user")); } else { return(RedirectToAction("Login", "Account")); } if (!ViewBag.User.IsAdmin) { return(RedirectToAction("Login", "Account")); } if (ModelState.IsValid) { var allAcc = accountsvc.GetAllAccount(); var currentAccount = allAcc.FirstOrDefault(it => it._id == model._id); currentAccount.FirstName = model.FirstName; currentAccount.LastName = model.LastName; currentAccount.Email = model.Email; currentAccount.WorkPosition = model.WorkPosition; currentAccount.Department = model.Department; currentAccount.Telephone = model.Telephone; currentAccount.BirthDate = model.BirthDate; currentAccount.ProjectCreatable = model.ProjectCreatable; if (model.IsSuspend) { currentAccount.SuspendDate = DateTime.Now; } else { currentAccount.SuspendDate = null; } accountsvc.EditAccount(currentAccount); return(RedirectToAction(nameof(AccountManage))); } return(View(model)); }
public async Task<AccountModel> EditAccountAsync(EditAccountModel model, long userId) { var entity = await accountRepo.FirstAsync(x => x.Id == model.Id); if (entity == null) throw new Exception("Account not exist!"); if (entity.UserId != userId) throw new Exception("You don't owner of account!"); entity.InitialAmount = model.InitialAmount; entity.IsCredit = model.IsCredit; entity.IsDebit = model.IsDebit; entity.Name = model.Name; entity.OveralTotal = model.OveralTotal; accountRepo.Update(entity); await unitOfWork.CommitAsync(); return ConvertEntityToAccountModel(entity); }
public ActionResult EditAccount(int id) { List <ChartOfAcc> editAccount; using (IDbConnection db = new SqlConnection(SqlAccess.GetConnectionString())) { editAccount = db.Query <ChartOfAcc>($"Select * from dbo.ChartOfAccounts Where AccountNumber = @ID", new { ID = id }).ToList(); } EditAccountModel e = new EditAccountModel(); e.AccountNumber = editAccount[0].AccountNumber; e.AccountName = editAccount[0].AccountName; e.AccountType = editAccount[0].AccountType; e.AccountDescription = editAccount[0].AccountDescription; e.Active = editAccount[0].Active; return(View(e)); }
public IHttpActionResult EditAccount(EditAccountModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Cad.UpdatePerson(model.FirstName, model.LastName, model.DoB, model.Phone, User.Identity.GetUserId()); return(GetResponse()); } catch (ConnectedApartmentsException e) { return(BadRequest(e.Message)); } catch (Exception) { return(InternalServerError()); } }
public ActionResult EditAccount(int id = 0) { var user = db.Users.Include(u => u.Webpages_Roles).FirstOrDefault(u => u.ID == id); if (user == null) { return(HttpNotFound()); } var model = new EditAccountModel(user); model.roles = user.Webpages_Roles.Select(wr => wr.RoleName).ToArray(); ViewBag.AllRoles = db.Webpages_Roles.ToList(); User currentUser = db.Users.Find(WebSecurity.CurrentUserId); int? companyID = currentUser.companyID; ViewBag.department_id = new SelectList(db.Departments.Where(dep => dep.companyID == companyID), "ID", "name", model.department_id); ViewBag.position_id = new SelectList(db.Positions.Where(dep => dep.companyID == companyID), "ID", "name", model.position_id); ViewBag.roles = new MultiSelectList(db.Webpages_Roles, "RoleName", "RoleName", model.roles); ViewBag.adminUser = (currentUser.superUser) ? true : false; return(View(model)); }
public ActionResult EditAccount(EditAccountModel model) { if (!ModelState.IsValid) { return(View()); } var user = _userService.GetUser(model.Id); user.IsAdmin = model.IsAdmin; if (!string.IsNullOrWhiteSpace(model.BadgeId)) { user.BadgeId = model.BadgeId; } if (!string.IsNullOrWhiteSpace(model.Name)) { user.Name = model.Name; } if (!string.IsNullOrWhiteSpace(model.Username)) { user.Username = model.Username; } if (!string.IsNullOrWhiteSpace(model.Username)) { user.DiscountPercentage = Math.Max(MinDiscount, Math.Min(MaxDiscount, model.DiscountPercentage)); } if (!string.IsNullOrWhiteSpace(model.Password)) { _userService.ResetPassword(user, model.Password); } var tempData = new TempDataFacade(TempData); tempData.SuccessMessage = model.Name + "'s account has been updated."; return(RedirectToAction("EditAccount", new { selectedUserId = model.Id })); }
public EditAccountTests() { facade = new Mock <IFacade>(); var username = "******"; var identity = new GenericIdentity(username, ""); var nameIdentityClaim = new Claim(ClaimTypes.NameIdentifier, username); identity.AddClaim(nameIdentityClaim); var principal = new Mock <IPrincipal>(); principal.Setup(p => p.Identity).Returns(identity); principal.Setup(p => p.IsInRole("Tenant")).Returns(true); model = new EditAccountModel() { DoB = new DateTime(1995, 03, 16), FirstName = "Vasileios", LastName = "Papadopoulos", Phone = "0123456789" }; controllerContext = new HttpControllerContext { RequestContext = { Principal = principal.Object } }; }
public ActionResult Edit(EditAccountModel model) { if (ModelState.IsValid) { //Cast enum Notification to an int before passing it int notificationInt = Convert.ToInt32(model.NotificationSchedule); //Users may choose to update their email, but we need the current one for //pulling the account. string currentEmail = RetrieveEmail(); //Calls UpdateAccount from the AccountProcessor class in DatabaseBusinessLogic folder if (UpdateAccount(model.FirstName, model.LastName, model.Phone, currentEmail, model.Email, notificationInt) == 1) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Error updating account"); } } return(View(model)); }
public JsonResult Edit(EditAccountModel model) { _accountFacade.Edit(model); return(Json(new { success = true })); }
public ActionResult EditAccount(EditAccountModel model, bool adminUser) { if (ModelState.IsValid) { var imageGUID = Guid.NewGuid(); string imageUrl = ""; if (model.image != null) { imageUrl = imageGUID + Path.GetExtension(model.image.FileName); string filePath = Path.Combine( Server.MapPath("~/Uploads/UserImages"), imageGUID + Path.GetExtension(model.image.FileName )); if (model.image.ContentLength > 102400) { MemoryStream target = new MemoryStream(); model.image.InputStream.CopyTo(target); var resizedImage = new ImageResizer(target.ToArray()); resizedImage.Resize(400, 200, false, ImageEncoding.Jpg90); resizedImage.SaveToFile(filePath); } else { model.image.SaveAs(filePath); } var images = Directory.GetFiles(Server.MapPath("~/Uploads/UserImages")); FileInfo old = new FileInfo(Server.MapPath("~/Uploads/UserImages") + "\\" + model.imageUrl); if (images.Contains(old.FullName)) { filePath = model.image.FileName; System.IO.File.Delete(Path.Combine(Server.MapPath("~/Uploads/UserImages"), model.imageUrl)); model.imageUrl = filePath; } model.imageUrl = imageUrl; } else if (model.image == null && model.imageUrl != null) { var images = Directory.GetFiles(Server.MapPath("~/Uploads/UserImages")); FileInfo old = new FileInfo(Server.MapPath("~/Uploads/UserImages") + "\\" + model.imageUrl); if (images.Contains(old.FullName)) { System.IO.File.Delete(Path.Combine(Server.MapPath("~/Uploads/UserImages"), model.imageUrl)); model.imageUrl = ""; } } if (adminUser && model.userID == WebSecurity.CurrentUserId) { model.position_id = null; model.department_id = null; } User usr = db.Users.Find(model.userID); usr.name = model.name; usr.password = model.Password; usr.username = model.UserName; usr.imageUrl = model.imageUrl; if (adminUser) { usr.departmentID = model.department_id; usr.positionID = model.position_id; usr.status = Convert.ToInt32(model.activeUser); usr.Webpages_Roles.Clear(); db.Entry(usr).State = EntityState.Modified; db.SaveChanges(); var roleProvider = (SimpleRoleProvider)Roles.Provider; if (model.roles != null) { roleProvider.AddUsersToRoles(new[] { model.UserName }, model.roles); } return(RedirectToAction("Index", "Home", null)); } } User currentUser = db.Users.Find(WebSecurity.CurrentUserId); int? companyID = currentUser.companyID; ViewBag.department_id = new SelectList(db.Departments.Where(dep => dep.companyID == companyID), "ID", "name", model.department_id); ViewBag.position_id = new SelectList(db.Positions.Where(dep => dep.companyID == companyID), "ID", "name", model.position_id); ViewBag.roles = new MultiSelectList(db.Webpages_Roles, "RoleName", "RoleName", model.roles); ViewBag.adminUser = (currentUser.superUser) ? true : false; return(View(model)); }
public ActionResult Edit(EditAccountModel model) { if (!RolesManager.IsAdministrator()) { return(RedirectToAction("UnAuthorized", "Error")); } if (ModelState.IsValid) { // Attempt to register the user try { var result = _db.UserProfiles.FirstOrDefault(x => x.UserId == model.UserId); if (result != null) { if (!string.IsNullOrEmpty(model.NewPassword)) { WebSecurity.ChangePassword(result.UserName, model.NewPassword, model.ConfirmPassword); } string roleName = null; switch (model.RoleId) { case 1: roleName = "Administrator"; break; case 2: roleName = "SuperUser"; break; case 3: roleName = "NormalUser"; break; } if (!Roles.IsUserInRole(result.UserName, roleName)) { var roles = Roles.GetRolesForUser(result.UserName); if (roles.Length > 0) { Roles.RemoveUserFromRoles(result.UserName, roles); } Roles.AddUserToRole(result.UserName, roleName); } result.UserName = model.UserName; _db.SaveChanges(); } ViewBag.Message = "Потребителя е редактиран успешно!"; return(RedirectToAction("Index")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public string EditAccount([FromBody] EditAccountModel request) { var accountResponse = twitterBlService.EditAccount(request.Id, request.FirstName, request.LastName, request.Password); return(ToJson(accountResponse)); }
private void ShowEditAccount() { EditAccountModel model = new EditAccountModel(); _uiVisualizerService.ShowDialog(new EditAccountViewModel(model, _pleaseWaitService, _messageService)); }
private static void EditSimpleProperties(EditAccountModel editRequest, UserAccountModel targetModel) { targetModel.Name = editRequest.NewName; }