public ActionResult AddNewBranch(AddBranchViewModel newBranch) { if (ModelState.IsValid) { Branch branch = _mapper.Map <Branch>(newBranch); branch.BranchIdentificator = _keyGenerator.GenerateNewId(); _context.branchRepository.AddBranch(branch); #region EntityLogs var logInfoAddBranch = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[0], LogDescriptions.DescriptionOfActionOnEntity["addBranch"]); _logger.AddBranchLog(branch, logInfoAddBranch); #endregion #region PersonalUserLogs var logInfoPersonalAddBranch = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["addBranch"], "Nazwa: " + branch.Name); _context.personalLogRepository.AddPersonalUserLogToAdminGroup(logInfoPersonalAddBranch); #endregion return(RedirectToAction("ConfirmationOfActionOnBranch", "Branches", new { branchIdentificator = branch.BranchIdentificator, typeOfAction = "Add" })); } return(View(newBranch)); }
public async Task <ActionResult> AddBranch(AddBranchViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, EmailConfirmed = true, BranchGoogleId = model.BranchGoogleId, BranchLocation = model.BranchLocation, BranchName = model.BranchName }; var result = await UserManager.CreateAsync(user, "Admin1!"); if (result.Succeeded) { //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); //Assign Role to user Here await this.UserManager.AddToRoleAsync(user.Id, model.RoleName); //Ends Here // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); TempData["success"] = "User successfully created!"; return(RedirectToAction("Index", "AspNetUsers")); } AddErrors(result); } // If we got this far, something failed, redisplay form TempData["error"] = "Errors when trying to create user!"; return(View(model)); }
public async Task <IActionResult> Post([FromBody] AddBranchViewModel model) { Guid?parentId = null; if (model == null) { return(BadRequest()); } if (model.ParentBranchId.HasValue) { var parentBranch = await _branchRepo.GetAsync(model.ParentBranchId.Value); if (parentBranch == null) { return(NotFound(Resources.Branchs.BranchResource.ParentBranchNotFound)); } parentId = parentBranch.Id; } if (await _branchRepo.IsExistCodeAsync(model.Code)) { ModelState.AddModelError("Code", Resources.Global.Common.ThisCodeExist); } if (await _branchRepo.IsExistNameAsync(model.Name)) { ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist); } if (!ModelState.IsValid) { return(BadRequest(ModelState.GetWithErrorsKey())); } var branch = new Branch(model.Name, model.Code, model.Note); if (parentId.HasValue) { branch.ParentId = parentId.Value; } var affectedRows = await _branchRepo.AddAsync(branch); if (affectedRows > 0) { _branchRepo.LoadReferences(branch); var viewModel = AutoMapper.Mapper.Map <BranchViewModel>(branch); return(CreatedAtRoute("GetBranch", new { id = branch.Number }, viewModel)); } return(BadRequest()); }
public ActionResult AddNewBranch(AddBranchViewModel newBranch) { if (ModelState.IsValid) { Branch branch = new Branch { Name = newBranch.Name }; return(RedirectToAction("AddNewBranchConfirmation", new { BranchName = newBranch.Name })); } return(View(newBranch)); }
public ActionResult AddBranch() { var model = new AddBranchViewModel(); var roles = context.Roles.ToList(); foreach (var r in roles) { model.RoleList.Add(new SelectListItem() { Text = r.Name, Value = r.Name }); } return(View(model)); }
public async Task <IActionResult> AddBranch([FromForm] AddBranchViewModel model) { model.BusinessId = 4; var baseUrl = _configuration["ApiBaseUrl"]; var url = baseUrl + "business/AddBranch"; var client = new RestClient(url); var request = new RestRequest(Method.POST); string json = JsonConvert.SerializeObject((AddBranchViewModel)model); request.AddJsonBody(json); request.AddHeader("cache-control", "no-cache"); request.AddParameter("Accept", "application/json"); request.AddParameter("Content-Type", "application/json"); var response = await client.ExecuteAsync(request); return(RedirectToAction("BusinessInformation", "Home")); }
public async Task <IActionResult> Add(AddBranchViewModel branchModel) { string fullAddress = branchModel.Address + " " + branchModel.Town; //TODO: make branch add friendly error page if (!ModelState.IsValid) { this.TempData.AddFailureMessage(string.Format(FailureAddItemMessage, fullAddress)); return(this.RedirectToAction(nameof(Index))); //return this.BadRequest(); } await branchesService.AddBranchAsync(branchModel.Town, branchModel.Address); this.TempData.AddSuccessMessage(string.Format(SuccessAddItemMessage, fullAddress)); return(this.RedirectToAction(nameof(Index))); }
public ActionResult Details(AddBranchViewModel model, OptionsViewModel moreInfo, bool clear) { List <Error> errors = new List <Error>(); if (ModelState.IsValid) { if (ServerValidationEnabled) { errors = _hrUnitOfWork.SiteRepository.CheckForm(new CheckParm { CompanyId = CompanyId, ObjectName = "FormBranch", TableName = "Branches", Columns = Models.Utils.GetColumnViews(ModelState), ParentColumn = "CompanyId", Culture = Language }); if (errors.Count() > 0) { foreach (var e in errors) { foreach (var errorMsg in e.errors) { ModelState.AddModelError(errorMsg.field, errorMsg.message); } } return(Json(Models.Utils.ParseFormErrors(ModelState))); } } } else { return(Json(Models.Utils.ParseFormErrors(ModelState))); } var sequence = _hrUnitOfWork.Repository <Branch>().Select(a => a.Code).DefaultIfEmpty(0).Max(); var MaxCode = sequence == 0 ? 1 : sequence + 1; var branch = new Branch(); if (model.Id == 0) // New { model.CompanyId = CompanyId; _hrUnitOfWork.BranchRepository.AddLName(Language, branch.Name, model.Name, model.LName); AutoMapper(new Models.AutoMapperParm { Destination = branch, Source = model, ObjectName = "FormBranch", Options = moreInfo, Transtype = TransType.Insert }); branch.CreatedTime = DateTime.Now; branch.CreatedUser = UserName; branch.Code = MaxCode; _hrUnitOfWork.BranchRepository.Add(branch); } else // Edit { branch = _hrUnitOfWork.BranchRepository.Find(a => a.Id == model.Id).FirstOrDefault(); AutoMapper(new Models.AutoMapperParm { Destination = branch, Source = model, ObjectName = "FormBranch", Options = moreInfo, Transtype = TransType.Update }); branch.ModifiedTime = DateTime.Now; branch.ModifiedUser = UserName; _hrUnitOfWork.BranchRepository.AddLName(Language, branch.Name, model.Name, model.LName); } string message = "OK"; var Errors = SaveChanges(Language); model.Id = branch.Id; if (clear) { model = new AddBranchViewModel(); } message += "," + (new JavaScriptSerializer()).Serialize(model); if (Errors.Count > 0) { message = Errors.First().errors.First().message; } return(Json(message)); }