public async Task <IActionResult> Put([FromRoute] Guid id, [FromBody] CreateBranchModel branchModel) { try { bool result = await _branchManager.Update(id, branchModel); if (!result) { return(BadRequest()); } return(Ok()); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } catch (KeyNotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Create(CreateBranchModel model) { IHttpActionResult httpActionResult; if (string.IsNullOrEmpty(model.Name)) { error.Add("Name is required"); } if (error.errors.Count == 0 && CheckPhoneNumber.CheckCorrectPhoneNumber(model.PhoneNumber)) { Branch branch = new Branch(); //branch.BranchCode = "CN" + RemoveSpacesAndSpecialCharacters.convertToUnSign(model.Name).ToUpper(); ; branch.BranchCode = model.BranchCode; branch.Name = model.Name; branch.Address = model.Address; branch.PhoneNumber = model.PhoneNumber; branch.CreatedDate = DateTime.Now; //branch.CreatedBy = User.Identity.Name; branch = db.Branches.Add(branch); db.SaveChanges(); httpActionResult = Ok(new BranchModel(branch)); } else { httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error); } return(httpActionResult); }
public async Task <Guid> CreateNewTestBranch(CreateBranchModel branch, TokenModel token) { var uri = new Uri($"{_publicApiServiceUrl}/branch"); var responseString = await SendRequestAsync(uri, HttpMethod.Post, JsonConvert.SerializeObject(branch), token); return(DeserializeResultFromResponseString <Guid>(responseString)); }
public async Task <ActionResult> _Create(CreateBranchModel model) { var nameResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"Administration/Branch/IsNameExist?id={null}&name={model.Name}"); if (nameResponse.isSuccess) { TempData["ErrorMessage"] = Language.Branch.ValidExistName; return(RedirectToAction("List")); } if (ModelState.IsValid) { var response = await WepApiMethod.SendApiAsync <int>(HttpVerbs.Post, $"Administration/Branch", model); if (response.isSuccess) { TempData["SuccessMessage"] = Language.Branch.AlertSuccessCreate; await LogActivity(Modules.Setting, "Create Parameter Branch", model); return(RedirectToAction("List")); } } TempData["ErrorMessage"] = Language.Branch.AlertFailCreate; return(RedirectToAction("List")); }
public async Task <ActionResult> _Create() { var model = new CreateBranchModel(); model.States = new SelectList(await GetStates(), "Id", "Name", 0); return(View(model)); }
public IHttpActionResult Post([FromBody] CreateBranchModel model) { var branch = new Branch { Name = model.Name, StateId = model.StateId, Display = true }; db.Branch.Add(branch); db.SaveChanges(); return(Ok(branch.Id)); }
public async Task <IActionResult> Post([FromBody] CreateBranchModel branchModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { // TODO can not adapt because CreateBranchModel has one object BranchContacts, but need has collection var branchEntity = branchModel.Adapt <Branch>(); Guid branchId = await _branchRepository.AddAsync(branchEntity); return(Ok(branchId)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> CreateBranch(CreateBranchModel model) { if (!ModelState.IsValid) { return(BadRequest("Geçersiz veri")); } // Yeni bir şube tanımlar. var branch = new Branch { DateCreated = DateTime.Now, FirmId = _currentFirm.Id, IsActive = true, Name = model.Name, CityId = Convert.ToInt32(model.City.Decrypt()) }; var branchId = await _branchService.CreateBranchAsync(branch); // Tanımlanan şubeye ait bir yönetici kullanıcı tanımlar. var user = new ApplicationUser { DateCreated = DateTime.Now, IsActive = true, Email = model.Email, EmailConfirmed = true, BranchId = branchId, Name = model.Name, NormalizedEmail = model.Email, NormalizedUserName = model.Email, UserName = model.Email, PhoneNumber = model.PhoneNumber, PhoneNumberConfirmed = true }; await _userService.CreateUserAsync(user, model.Password, "Branch"); _logger.LogInformation(string.Format("#{0} firması {1} şubesi ve {2} şube kullanıcısı oluşturdu.", _currentUser.Name, branch.Name, user.Name)); return(Ok("Şube kaydedildi")); }
/// <inheritdoc /> public async Task <bool> Update(Guid id, CreateBranchModel request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!(await _branchRepository.HasAsync(id))) { throw new KeyNotFoundException(); } var branch = request.Adapt <Branch>(); branch.Id = id; if (request.BranchContacts != null) { branch.BranchContacts = new List <BranchContact>() { request.BranchContacts }; } return(await _branchRepository.UpdateAsync(branch)); }