public GeneralResponse AddCourierEmployee(AddCourierEmployeeRequest request, Guid CreateEployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                CourierEmployee courierEmployee = new CourierEmployee();
                courierEmployee.ID             = Guid.NewGuid();
                courierEmployee.CreateDate     = PersianDateTime.Now;
                courierEmployee.CreateEmployee = _employeeRepository.FindBy(CreateEployeeID);
                courierEmployee.Address        = request.Address;
                courierEmployee.FirstName      = request.FirstName;
                courierEmployee.LastName       = request.LastName;
                courierEmployee.Mobile         = request.Mobile;
                courierEmployee.Phone          = request.Phone;
                courierEmployee.RowVersion     = 1;

                _courierEmployeeRepository.Add(courierEmployee);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
        public GeneralResponse EditCourierEmployee(EditCourierEmployeeRequest request, Guid ModifiedEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                CourierEmployee courierEmployee = new CourierEmployee();
                courierEmployee = _courierEmployeeRepository.FindBy(request.ID);

                courierEmployee.ModifiedDate     = PersianDateTime.Now;
                courierEmployee.ModifiedEmployee = _employeeRepository.FindBy(ModifiedEmployeeID);
                courierEmployee.Address          = request.Address;
                courierEmployee.FirstName        = request.FirstName;
                courierEmployee.LastName         = request.LastName;
                courierEmployee.Phone            = request.Phone;
                courierEmployee.Mobile           = request.Mobile;

                #region Row Version Check

                if (courierEmployee.RowVersion != request.RowVersion)
                {
                    response.ErrorMessages.Add("EditConcurrencyKey");
                    return(response);
                }
                else
                {
                    courierEmployee.RowVersion += 1;
                }

                if (courierEmployee.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in courierEmployee.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }


                #endregion

                _courierEmployeeRepository.Save(courierEmployee);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
Exemple #3
0
 public static CourierEmployeeView ConvertToCourierEmployeeView(this CourierEmployee courierEmployee)
 {
     return(Mapper.Map <CourierEmployee, CourierEmployeeView>(courierEmployee));
 }