public async Task <IActionResult> Post([FromBody] AddCurrencyViewModel model) { if (model == null) { return(BadRequest()); } if (await _currencyRepo.IsExistCodeAsync(model.Code)) { ModelState.AddModelError("Code", Resources.Global.Common.ThisCodeExist); } if (await _currencyRepo.IsExistNameAsync(model.Name)) { ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist); } if (!ModelState.IsValid) { return(BadRequest(ModelState.GetWithErrorsKey())); } var currency = new Currency(model.Code, model.Name, model.Value, model.PartName, model.PartRate, model.Note); var affectedRows = await _currencyRepo.AddAsync(currency); if (affectedRows > 0) { var viewModel = _modelFactory.CreateViewModel(currency, _defaultKeysOptions.Value.CurrencyId); return(CreatedAtRoute("GetCurrency", new { id = currency.Number }, viewModel)); } return(BadRequest()); }
public ActionResult Add(AddCurrencyViewModel model) { if (!ModelState.IsValid) { if (!this.IsMegaAdmin()) { model.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()); } else { model.Organisations = this.organisationService.GetAll().ToList() .ConvertAll(x => new OrganisationViewModel { Id = x.Id, Name = x.Name }); } return(View(model)); } var userORg = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()); if (this.IsMegaAdmin()) { userORg = model.SeletedOrganisationId; } //Check is there a currency with the same code if (this.currencyService.Exist(model.Code, userORg)) { this.ModelState.AddModelError("Code", CurrencyTr.SameCodeError); if (!this.IsMegaAdmin()) { model.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()); } else { model.Organisations = this.organisationService.GetAll().ToList() .ConvertAll(x => new OrganisationViewModel { Id = x.Id, Name = x.Name }); } return(View(model)); } this.currencyService.Add(new Currency { Code = model.Code, Description = model.Description, OrganisationId = model.SeletedOrganisationId }); return(Redirect("/HelpModule/Currency/Index")); }
public IActionResult AddCurrency(AddCurrencyViewModel model) { var addResult = _currencyService.Create(model.CurrencyDto); if (!addResult.Success) { ModelState.ValidateModel(addResult.ValidationErrors, nameof(CurrencyDto)); return(View(model)); } this.AddToastrMessage("Başarılı!", addResult.Message, ToastrEnum.Type.Success); return(RedirectToAction(nameof(CurrencyDetail), new { currencyId = addResult.Data.Id })); }
public ActionResult Add() { var viewModel = new AddCurrencyViewModel(); if (!this.IsMegaAdmin()) { viewModel.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()); } else { viewModel.Organisations = this.organisationService.GetAll().ToList() .ConvertAll(x => new OrganisationViewModel { Id = x.Id, Name = x.Name }); } return(View(viewModel)); }