public BaseResponse <Department> AddDepartment(Department model) { var 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 lstDepartment = _departmentRepository.GetAll().Where(n => n.Code.ToLower() == model.Code.ToLower()).ToList(); if (lstDepartment.Count() == 0) { model.CreatedOn = DateTime.Now; response.Value = _departmentRepository.Add(model); _applicationLoggingRepository.Log("EVENT", "ADD", "Department", model.Id.ToString(), "", "", model, "", HttpContext.Current.Request.UserHostAddress, model.CreatedBy); } else { response.Message = "Mã đơn vị đã tồn tại"; response.IsSuccess = false; } } catch (Exception ex) { response.IsSuccess = false; response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace; } return(response); }
public BaseResponse <ComplexRoleOfUser> AddRolesForUser(List <ComplexRoleOfUser> models) { var response = new BaseResponse <ComplexRoleOfUser>(); AspNetUserRole userRole; try { foreach (var model in models) { userRole = new AspNetUserRole(); userRole.RoleId = model.RoleId; userRole.Grant = model.Grant; userRole.UserId = model.UserId; _aspNetUserRolesRepository.Add(userRole); try { _applicationLoggingRepository.Log("EVENT", "ADD", "AspNetGroupRoles", model.RoleId + "," + model.UserId, "", "", model, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy); } catch { } } } catch (Exception ex) { response.IsSuccess = false; response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace; } response.IsSuccess = true; return(response); }
public BaseResponse <SystemConfig> AddSystemConfig(SystemConfig model) { var response = new BaseResponse <SystemConfig>(); var errors = Validate <SystemConfig>(model, new SystemConfigValidator()); if (errors.Count() > 0) { BaseResponse <SystemConfig> errResponse = new BaseResponse <SystemConfig>(model, errors); errResponse.IsSuccess = false; return(errResponse); } try { model.CreatedOn = DateTime.Now; response.Value = _systemConfigRepository.Add(model); try { _applicationLoggingRepository.Log("EVENT", "CREATE", "SystemConfig", response.Value.Id.ToString(), "", "", model, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy); } catch { } if (model.IsSystemConfig == false) { DepartmentQuery query = new DepartmentQuery(); query.Keyword = ""; query.ParentId = 0; query.Active = true; List <SPGetDepartment_Result> arrDepartments = _departmentRepository.Filter(query).Where(n => n.ParentId != 0).ToList(); SystemConfigDepartment config; if (arrDepartments.Count() > 0) { foreach (var item in arrDepartments) { config = new SystemConfigDepartment(); config.ConfigId = response.Value.Id; config.Value = model.Value; config.Description = model.Description; config.DepartmentId = item.Id; config.CreatedBy = model.CreatedBy; config.CreatedOn = model.CreatedOn; config.EditedBy = model.EditedBy; config.EditedOn = model.EditedOn; _systemConfigDepartmentRepository.Add(config); try { _applicationLoggingRepository.Log("EVENT", "CREATE", "SystemConfigDepartment", response.Value.Id.ToString(), "", "", config, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy); } catch { } } } } } catch (Exception ex) { response.IsSuccess = false; response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace; } return(response); }
public BaseResponse <Customer> AddCustomer(Customer model) { var response = new BaseResponse <Customer>(); var errors = Validate <Customer>(model, new CustomerValidator()); if (errors.Count() > 0) { BaseResponse <Customer> errResponse = new BaseResponse <Customer>(model, errors); errResponse.IsSuccess = false; return(errResponse); } try { var listCustomer = _customerRepository.GetAll().Where(x => x.Code.ToLower() == model.Code.ToLower() && x.DepartmentId == model.DepartmentId).ToList(); if (listCustomer.Count > 0) { response.IsSuccess = false; response.Message = "Mã khách hàng đã tồn tại"; } else { model.CreatedOn = DateTime.Now; response.Value = _customerRepository.Add(model); try { _applicationLoggingRepository.Log("EVENT", "CREATE", "Customer", response.Value.Id.ToString(), "", "", model, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy); } catch { } } } catch (Exception ex) { response.IsSuccess = false; response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace; } return(response); }