public async Task <IActionResult> FunctionSave(TRequest <FunctionRequest> request) { if (request == null) { return(NotFound()); } var response = new Response <int>(); try { if (request.value.Id == 0) { response.Data = _functionService.Add(request.value); response.Message = "Thêm thành công"; response.Success = true; } else { response.Data = _functionService.Update(request.value); response.Message = "Sửa thành công"; response.Success = true; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message + "," + ex.InnerException; } return(Ok(response)); }
public async Task <IActionResult> SaveEntity(FunctionViewModel functionViewModel) { if (!ModelState.IsValid) { var allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (!_functionService.CheckExistedId(functionViewModel.Id)) { var notificationId = Guid.NewGuid().ToString(); var announcement = new AnnouncementViewModel { Title = User.GetSpecificClaim("FullName"), DateCreated = DateTime.Now, Content = $"Function {functionViewModel.Name} has been created", Id = notificationId, UserId = User.GetUserId(), Image = User.GetSpecificClaim("Avatar"), Status = Status.Active }; var announcementUsers = new List <AnnouncementUserViewModel>() { new AnnouncementUserViewModel() { AnnouncementId = notificationId, HasRead = false, UserId = User.GetUserId() } }; _functionService.Add(announcement, announcementUsers, functionViewModel); await _hubContext.Clients.All.SendAsync("ReceiveMessage", announcement); } else { var notificationId = Guid.NewGuid().ToString(); var announcement = new AnnouncementViewModel { Title = User.GetSpecificClaim("FullName"), DateCreated = DateTime.Now, Content = $"Function {functionViewModel.Name} has been updated", Id = notificationId, UserId = User.GetUserId(), Image = User.GetSpecificClaim("Avatar"), Status = Status.Active }; var announcementUsers = new List <AnnouncementUserViewModel>() { new AnnouncementUserViewModel() { AnnouncementId = notificationId, HasRead = false, UserId = User.GetUserId() } }; _functionService.Update(announcement, announcementUsers, functionViewModel); await _hubContext.Clients.All.SendAsync("ReceiveMessage", announcement); } _functionService.Save(); return(new OkObjectResult(functionViewModel)); } }
public IActionResult Create([FromBody] FunctionViewModel functionViewModel) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } _functionService.Add(functionViewModel); _functionService.Save(); return(new NoContentResult()); }
public IActionResult Create(FunctionViewModel functionVm) { try { if (ModelState.IsValid) { var categories = _functionService.GetAll(); functionVm.Categories = _functionService.FunctionsSelectListItem(id: functionVm.Id); var errorByProductItemName = "Mã chức năng đã tồn tại"; if (_functionService.ValidateAddUniqueCode(functionVm)) { ModelState.AddModelError("", errorByProductItemName); return(View(functionVm)); } if (_functionService.ValidateAddOrder(functionVm)) { ModelState.AddModelError("", "Thứ tự đã tồn tại"); return(View(functionVm)); } if (functionVm.ParentId == 0) { functionVm.ParentId = null; } _functionService.Add(functionVm); _functionService.Save(); return(Redirect("/admin/function/index")); } else { // IEnumerable<ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); // return new BadRequestObjectResult(allErrors); // return BadRequest(ModelState.Select(x => x.Value.Errors).FirstOrDefault(y => y.Count > 0)?.First() // .ErrorMessage); IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); foreach (var item in allErrors) { var message = item.ErrorMessage; } return(View(functionVm)); } } catch (Exception ex) { return(Redirect("/admin/function/index")); } }
public ActionResult Create(FunctionVm functionVm) { if (ModelState.IsValid) { var function = new Function(); function.UpdateFunction(functionVm); function.CreatedBy = 1; function.CreatedDate = DateTime.Now; _functionService.Add(function); _functionService.Save(); TempData["MessageSuccess"] = Message.CreateSuccess; return(RedirectToAction("Index")); } TempData["MessageError"] = Message.CreateError; return(View()); }
public IActionResult SaveEntity(FunctionViewModel functionVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (string.IsNullOrWhiteSpace(functionVm.Id)) { _functionService.Add(functionVm); } else { _functionService.Update(functionVm); } return(new OkObjectResult(functionVm)); } }
public async Task <IActionResult> SaveEntity(FunctionViewModel functionVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (functionVm.IsUpdated) { await _functionService.Update(functionVm); } else { await _functionService.Add(functionVm); } _functionService.Save(); return(new OkObjectResult(functionVm)); }
public IActionResult SaveEntity(FunctionViewModel functionViewModel) { if (!ModelState.IsValid) { var allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (!_functionService.CheckExistedId(functionViewModel.Id)) { _functionService.Add(functionViewModel); } else { _functionService.Update(functionViewModel); } _functionService.Save(); return(new OkObjectResult(functionViewModel)); } }
public IActionResult SaveEntity(FunctionViewModel functionVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (functionVm.Id.Equals(Guid.Empty)) { _functionService.Add(functionVm); } else { _functionService.Update(functionVm); } _functionService.Save(); return(new OkObjectResult(functionVm)); } }
public IActionResult SaveEntity(FunctionViewModel productVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { //productVm.SeoAlias = TextHelper.ToUnsignString(productVm.Name); if (productVm.Id == null) { _functionService.Add(productVm); } else { _functionService.Update(productVm); } _functionService.Save(); return(new OkObjectResult(productVm)); } }
public async Task <IActionResult> Add([FromBody] FunctionViewModel functionVm) { var hasPermission = await _authorizationService.AuthorizeAsync(User, "FUNCTION", Operations.Create); if (hasPermission.Succeeded == false) { return(new BadRequestObjectResult(CommonConstants.Forbidden)); } if (ModelState.IsValid) { try { _functionService.Add(functionVm); _functionService.SaveChanges(); return(new OkObjectResult(functionVm)); } catch (Exception ex) { return(new BadRequestObjectResult(ex)); } } return(new BadRequestObjectResult(ModelState)); }
private async void btnThem_Click(object sender, EventArgs e) { btnThem.Text = btnThem.Text.Equals("Tạo mới màn hình") ? "Lưu" : "Tạo mới màn hình"; if (btnThem.Text.Equals("Tạo mới màn hình")) // An nut them lan 2 { if (!isValid()) { MessageBox.Show("Ban phai nhap day du thông tin !"); btnThem.Text = "Lưu"; return; } //Code GenericResult rs = _functionService.Add(new FunctionViewModel() { Name = pName, URL = pURL, ParentId = pParentId, IconCss = pIconCSS, SortOrder = int.Parse(pSortOder), Status = pStatus.Equals("on") ? Status.Active : Status.InActive }); FormHelper.showDialog(rs); //End Code await loadGvFunction(); update_Edit(); datagv_ManHinh.Enabled = true; setBtnBack_False(); } else //Vua nhan nut them { saveStament(); setBtnBack_True(); reStart(); datagv_ManHinh.Enabled = false; } }