public GeneralResponse EditQueryEmployee(EditQueryEmployeeRequest request) { GeneralResponse response = new GeneralResponse(); QueryEmployee queryEmployee = new QueryEmployee(); queryEmployee = _queryEmployeeRepository.FindBy(request.ID); if (queryEmployee != null) { try { queryEmployee.ModifiedDate = PersianDateTime.Now; queryEmployee.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID); if (request.EmployeeID != null) { queryEmployee.Employee = this._employeeRepository.FindBy(request.EmployeeID); } if (request.QueryID != null) { queryEmployee.Query = this._queryRepository.FindBy(request.QueryID); } if (queryEmployee.RowVersion != request.RowVersion) { response.ErrorMessages.Add("EditConcurrencyKey"); return(response); } else { queryEmployee.RowVersion += 1; } if (queryEmployee.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in queryEmployee.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } _queryEmployeeRepository.Save(queryEmployee); _uow.Commit(); ////response.success = true; } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } } else { response.ErrorMessages.Add("NoItemToEditKey"); } return(response); }
public ActionResult Edit(string id, QueryEmployeeDetailView queryEmployeeDetailView) { #region Access Check bool hasPermission = GetEmployee().IsGuaranteed("QueryEmployee_Update"); if (!hasPermission) { ModelState.AddModelError("", "AccessDenied"); return(View(queryEmployeeDetailView)); } #endregion queryEmployeeDetailView.EmployeeView = GetEmployee(); if (ModelState.IsValid) { try { EditQueryEmployeeRequest request = new EditQueryEmployeeRequest(); request.ID = Guid.Parse(id); request.ModifiedEmployeeID = GetEmployee().ID; //request.EmployeeID = queryEmployeeDetailView.QueryEmployeeView.EmployeeID; //request.QueryID = queryEmployeeDetailView.QueryEmployeeView.QueryID; //request.RowVersion = queryEmployeeDetailView.QueryEmployeeView.RowVersion; GeneralResponse response = this._queryEmployeeService.EditQueryEmployee(request); if (response.success) { return(RedirectToAction("Index")); } else { foreach (string error in response.ErrorMessages) { ModelState.AddModelError("", error); } return(View(queryEmployeeDetailView)); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(queryEmployeeDetailView)); } } return(View(queryEmployeeDetailView)); }