public GeneralResponse AddFiscal(AddFiscalRequest request) { GeneralResponse response = new GeneralResponse(); try { Fiscal fiscal = new Fiscal(); fiscal.ID = Guid.NewGuid(); fiscal.CreateDate = PersianDateTime.Now; fiscal.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID); fiscal.Cost = request.Cost; if (request.CustomerID != null && request.CustomerID != Guid.Empty) { fiscal.Customer = this._customerRepository.FindBy(request.CustomerID); } else if (request.Phone != null) { fiscal.Customer = _customerRepository.FindByPhoneCode(request.Phone).First(); } fiscal.DocumentSerial = request.DocumentSerial; fiscal.DocumentType = request.DocumentType; fiscal.Note = request.Note; fiscal.MoneyAccount = _moneyAccountRepository.FindBy(request.MoneyAccountID); fiscal.InvestDate = request.InvestDate; fiscal.Confirm = ConfirmEnum.NotChecked; fiscal.ChargeStatus = ChargeStatus.NotChecked; fiscal.ForCharge = request.ForCharge; fiscal.FollowNumber = NewFollowNumber; fiscal.RowVersion = 1; #region Validation if (fiscal.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in fiscal.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } #endregion _fiscalRepository.Add(fiscal); _uow.Commit(); // for retriving FollowNumber response.ObjectAdded = _fiscalRepository.FindBy(fiscal.ID).ConvertToFiscalView(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { response.ErrorMessages.Add(ex.InnerException.Message); if (ex.InnerException.InnerException != null) { response.ErrorMessages.Add(ex.InnerException.InnerException.Message); } } } return(response); }
public GeneralResponse EditFiscal(EditFiscalRequest request) { GeneralResponse response = new GeneralResponse(); Fiscal fiscal = new Fiscal(); fiscal = _fiscalRepository.FindBy(request.ID); if (fiscal != null) { try { // Check If Editable or not if ((int)fiscal.Confirm == 2) { response.ErrorMessages.Add("FiscalCanNotEditKey"); return(response); } fiscal.ModifiedDate = PersianDateTime.Now; fiscal.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID); fiscal.Cost = request.Cost; fiscal.DocumentSerial = request.DocumentSerial; fiscal.DocumentType = request.DocumentType; fiscal.Note = request.Note; fiscal.InvestDate = request.InvestDate; if (fiscal.MoneyAccount.ID != request.ModifiedEmployeeID) { fiscal.MoneyAccount = _moneyAccountRepository.FindBy(request.MoneyAccountID); } fiscal.ChargeStatus = request.ChargeStatus; fiscal.SerialNumber = request.SerialNumber; fiscal.ForCharge = request.ForCharge; fiscal.Confirm = ConfirmEnum.NotChecked; #region RowVresion Check if (fiscal.RowVersion != request.RowVersion) { response.ErrorMessages.Add("EditConcurrencyKey"); return(response); } else { fiscal.RowVersion += 1; } #endregion #region Validation if (fiscal.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in fiscal.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } #endregion _fiscalRepository.Save(fiscal); _uow.Commit(); response.rowVersion = fiscal.RowVersion; } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } } else { response.ErrorMessages.Add("NoItemToEditKey"); } return(response); }