Exemplo n.º 1
0
        public GeneralResponse EditleveTypes(IEnumerable <EditLevelTypeRequest> requests, Guid EmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                foreach (EditLevelTypeRequest request in requests)
                {
                    LevelType levelTypes = new LevelType();
                    levelTypes = _levelTypeRepository.FindBy(request.ID);
                    levelTypes.ModifiedDate     = PersianDateTime.Now;
                    levelTypes.ModifiedEmployee = _employeeRepository.FindBy(EmployeeID);
                    if (request.Title != null)
                    {
                        levelTypes.Title = request.Title;
                    }

                    #region Validation

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

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

                        return(response);
                    }

                    #endregion

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

            return(response);
        }
Exemplo n.º 2
0
        public GeneralResponse AddLevelTypes(IEnumerable <AddLevelTypeRequest> requests, Guid EmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                foreach (AddLevelTypeRequest request in requests)
                {
                    LevelType levelType = new LevelType();
                    levelType.ID             = Guid.NewGuid();
                    levelType.Title          = request.Title;
                    levelType.CreateDate     = PersianDateTime.Now;
                    levelType.CreateEmployee = _employeeRepository.FindBy(EmployeeID);

                    #region validation

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

                        return(response);
                    }
                    #endregion

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

            return(response);
        }