Ejemplo n.º 1
0
        public DepartmentModel GetById(int Id)
        {
            var model = new DepartmentModel();
            var data  = departmentRepository.FindBy(x => x.departmentId == Id);

            Mapper.Map(data, model);
            return(model);
        }
Ejemplo n.º 2
0
        public BaseResponse <Department> UpdateDepartment(Department model)
        {
            BaseResponse <Department> response = new BaseResponse <Department>();
            var errors = Validate <Department>(model, new DepartmentValidator());

            if (errors.Count() > 0)
            {
                BaseResponse <Department> errResponse = new BaseResponse <Department>(model, errors);
                errResponse.IsSuccess = false;
                return(errResponse);
            }
            try
            {
                var department = _departmentRepository.GetById(model.Id);
                if (department.Code != model.Code)
                {
                    IEnumerable <Department> lstDepartment = _departmentRepository.FindBy(x => x.Code.ToLower() == model.Code.ToLower());
                    if (lstDepartment.Count() > 0)
                    {
                        response.IsSuccess = false;
                        response.Message   = "Mã đơn vị đã tồn tại";
                    }
                    else
                    {
                        model.EditedOn = DateTime.Now;
                        response.Value = _departmentRepository.Update(department, model);
                        _applicationLoggingRepository.Log("EVENT", "UPDATE", "Department", model.Id.ToString(), "", "", model, "", HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                    }
                }
                else
                {
                    model.EditedOn = DateTime.Now;
                    response.Value = _departmentRepository.Update(department, model);
                    _applicationLoggingRepository.Log("EVENT", "UPDATE", "Department", model.Id.ToString(), "", "", model, "", HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }