public ActionResult Create([FromBody] RegionViewModel vm) { var region = vm.ToModel(); var res = _bo.Create(region); return(StatusCode(res.Success ? (int)HttpStatusCode.OK : (int)HttpStatusCode.InternalServerError)); }
public async Task <IActionResult> Create(RegionViewModel vm) { if (ModelState.IsValid) { var model = vm.ToModel(); var createOperation = await _bo.CreateAsync(model); if (!createOperation.Success) { return(OperationErrorBackToIndex(createOperation.Exception)); } if (!createOperation.Result) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message); ViewData["Title"] = "Create Region"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "Create", Controller = "Regions", Icon = "fa-search", Text = "Create" }); ViewData["BreadCrumbs"] = crumbs; return(View(vm)); } return(OperationSuccess("The record was successfuly created")); } return(View(vm)); }
public async Task <IActionResult> Edit(Guid id, RegionViewModel vm) { if (ModelState.IsValid) { var getOperation = await _bo.ReadAsync(id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } var result = getOperation.Result; if (!vm.CompareToModel(result)) { result = vm.ToModel(result); var updateOperation = await _bo.UpdateAsync(result); if (!updateOperation.Success) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception); getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } vm = RegionViewModel.Parse(getOperation.Result); ViewData["Title"] = "Edit Region"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit" }); ViewData["BreadCrumbs"] = crumbs; return(View(vm)); } if (!updateOperation.Result) { TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message); getOperation = await _bo.ReadAsync((Guid)id); if (!getOperation.Success) { return(OperationErrorBackToIndex(getOperation.Exception)); } if (getOperation.Result == null) { return(RecordNotFound()); } vm = RegionViewModel.Parse(getOperation.Result); ViewData["Title"] = "Edit Region"; var crumbs = GetCrumbs(); crumbs.Add(new BreadCrumb() { Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit" }); ViewData["BreadCrumbs"] = crumbs; return(View(vm)); } else { return(OperationSuccess("The record was successfuly updated")); } } } return(RedirectToAction(nameof(Index))); }