public ServiceModel DeleteStockTransaction(int stockTransactionId) { var result = new ServiceModel(); var data = stockTransactionReporsitory.GetById(stockTransactionId); if (data == null) { result.Errors.Add(new ValidationResult(localizationService.GetLocalizedText("ErrorMessage.InvalidRequest", IMSAppConfig.Instance.CurrentLanguage, "Invalid Request!!!"))); return(result); } exceptionService.Execute((m) => { stockTransactionReporsitory.Delete(data); }, result); if (result.HasError) { return(result); } result.Message = localizationService.GetLocalizedText("Common.DeleteSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Deleted successfully."); return(result); }
public ItemRequestViewModel SavePersonalItemRequest(ItemRequestViewModel model) { exceptionService.Execute((m) => { model.DocumentSetupId = (int)eDocumentSetup.ItemRequest; if (model.Details.Count == 0) { model.Errors.Add(new ValidationResult("Please enter detail.", new string[] { "" })); } if (model.Errors.Any()) { return; } if (!model.Validate()) { return; } model.Date = model.DateBS.GetDate(); var entity = new ItemRequest(); if (model.Id > 0) { entity = itemRequestRepository.GetById(model.Id); entity.Date = model.Date; entity.Remarks = model.Remarks; itemRequestDetailRepository.DeleteRange(entity.ItemRequestDetails); } else { entity = AutomapperConfig.Mapper.Map <ItemRequest>(model); itemRequestRepository.Insert(entity); } foreach (var item in model.Details) { var detail = AutomapperConfig.Mapper.Map <ItemRequestDetail>(item); detail.ItemRequestId = entity.Id; itemRequestDetailRepository.Insert(detail); } if (model.Id == 0) { model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Data saved successfully."); } else { model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Save changes successfully."); } }, model); return(model); }
public TestLogViewModel SaveTestLog(TestLogViewModel model) { exceptionService.Execute((m) => { if (!model.Validate()) { return; } var entity = new TestLog(); if (model.Id > 0) { entity = testLogRepository.GetById(model.Id); entity.IsResolved = model.IsResolved; entity.ResolvedBy = model.ResolvedBy; entity.ResolvedDate = model.ResolvedDate; entity.ResolvedRemarks = model.ResolvedRemarks; testLogRepository.Update(entity); } else { model.Date = DateTime.Now; model.ResolvedDate = null; entity = AutomapperConfig.Mapper.Map <TestLog>(model); testLogRepository.Insert(entity); model.Id = entity.Id; } if (model.Id == 0) { model.Message = localizationService.GetLocalizedText("Message.RecordSavedSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Record saved succeeded."); } else { model.Message = localizationService.GetLocalizedText("Message.RecordUpdatedSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Record update succeeded."); } }, model); return(model); }
public UserViewModel SaveUser(UserViewModel model) { exceptionService.Execute((m) => { if (!InternetConnectionIsAvailable) { model.AddModelError(x => x.Email, "Message.NoInternetConnection", "Internet connection is not available, please try again later."); } if (model.HasError) { return; } var duplicateUserName = userRepository.Table.Any(x => x.UserId != model.UserId && x.Username == model.Username); if (duplicateUserName) { model.AddModelError(x => x.Username, "Message.Duplicate", string.Format("{0} already exists, please use another.", model.GetDisplayName(x => x.Username))); } if (model.HasError) { return; } if (!model.Validate()) { return; } var entity = new User(); if (model.UserId > 0) { entity = userRepository.GetById(model.UserId); userRepository.Update(entity); var employee = employeeRepository.GetById(model.EmployeeId); if (employee != null) { employee.UserId = model.UserId; employeeRepository.Update(employee); } var savedUser = employeeRepository.GetById(model.EmployeeId).User; if (savedUser != null) { var savedRoles = savedUser.UserRoles; if (savedRoles != null) { userRoleRepository.DeleteRange(savedRoles); } } if (employee != null && model.Roles != null && model.Roles.Any() && savedUser != null) { var roles = model.Roles.Select(x => x.Value); foreach (var r in roles) { userRoleRepository.Insert(new UserRole { UserId = employee.UserId.Value, RoleId = r, RoleGrantedFrom = DateTime.Now }); } } } else { var encServ = new EncryptionService(); var generatedPassword = encServ.RandomString(5); model.IsActive = true; model.Salt = encServ.CreateSaltKey(10); model.Password = encServ.CreatePasswordHash(generatedPassword, model.Salt); entity = AutomapperConfig.Mapper.Map <User>(model); userRepository.Insert(entity); model.UserId = entity.UserId; var employee = employeeRepository.GetById(model.EmployeeId); if (employee != null) { employee.UserId = model.UserId; employeeRepository.Update(employee); } if (employee != null && model.Roles != null && model.Roles.Any()) { var roles = model.Roles.Select(x => x.Value); foreach (var r in roles) { userRoleRepository.Insert(new UserRole { UserId = employee.UserId.Value, RoleId = r, RoleGrantedFrom = DateTime.Now }); } } if (employee != null && employee.Email != null) { var template = notificationService.EmailTemplate(NTAEnum.eEmailTemplateType.UserCreated); var subject = template.Subject; var body = template.TemplateBody.Replace("{EmployeeName}", employee.Name) .Replace("{UserName}", model.Username) .Replace("{Password}", generatedPassword); var messageBody = body; ServiceModel sm = notificationService.SendEmail(employee.Email, null, null, subject, messageBody, null, true, true); } } if (model.UserId == 0) { model.Message = localizationService.GetLocalizedText("Message.RecordSavedSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Record saved succeeded."); } else { model.Message = localizationService.GetLocalizedText("Message.RecordUpdatedSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Record update succeeded."); } }, model); return(model); }
public EmployeeProfileViewModel SaveProfile(EmployeeProfileViewModel model) { exceptionService.Execute((m) => { var dob = model.DateOfBirthBS.GetDate(); if (dob.IsFutureDate()) { model.AddModelError(x => x.DateOfBirthBS, "DobCanNotBeFutureDate", "Date of birth can not be future date."); } model.DateOfBirth = dob; var appointmentDate = model.AppointmentDateBS.GetDate(); if (appointmentDate.IsFutureDate()) { model.AddModelError(x => x.AppointmentDateBS, "Message.CanNotBeFutureDate", string.Format("{0} can not be future date.", model.GetDisplayName(x => x.AppointmentDateBS))); } model.AppointmentDate = appointmentDate; var dateTo20YrsofServiceDuration = model.DateTo20YrsofServiceDurationBS.GetDate(); if (dateTo20YrsofServiceDuration.IsPastDate()) { model.AddModelError(x => x.DateTo20YrsofServiceDurationBS, "Message.CanNotBeFutureDate", string.Format("{0} can not be past date.", model.GetDisplayName(x => x.DateTo20YrsofServiceDurationBS))); } model.DateTo20YrsofServiceDuration = dateTo20YrsofServiceDuration; var dateTo58YrsOld = model.DateTo58YrsOldBS.GetDate(); if (dateTo58YrsOld.IsPastDate()) { model.AddModelError(x => x.DateTo58YrsOldBS, "Message.CanNotBeFutureDate", string.Format("{0} can not be past date.", model.GetDisplayName(x => x.DateTo58YrsOldBS))); } model.DateTo58YrsOld = dateTo58YrsOld; var citizenshipIssuedDate = model.CitizenshipIssuedDateBS.GetDate(); if (citizenshipIssuedDate.IsFutureDate()) { model.AddModelError(x => x.CitizenshipIssuedDateBS, "Message.CanNotBeFutureDate", string.Format("{0} can not be future date.", model.GetDisplayName(x => x.CitizenshipIssuedDateBS))); } model.CitizenshipIssuedDate = citizenshipIssuedDate == DateTime.MinValue ? (DateTime?)null : citizenshipIssuedDate; var passportIssuedDate = model.PassportIssuedDateBS.GetDate(); if (passportIssuedDate.IsFutureDate()) { model.AddModelError(x => x.PassportIssuedDateBS, "Message.NoFutureDate", string.Format("{0} cannot be future date.", model.GetDisplayName(x => x.PassportIssuedDateBS))); } model.PassportIssuedDate = passportIssuedDate == DateTime.MinValue ? (DateTime?)null : passportIssuedDate; var driverLicenseIssuedDate = model.DriverLicenseIssuedDateBS.GetDate(); if (driverLicenseIssuedDate.IsFutureDate()) { model.AddModelError(x => x.DriverLicenseIssuedDateBS, "Message.NoFutureDate", string.Format("{0} cannot be future date.", model.GetDisplayName(x => x.DriverLicenseIssuedDateBS))); } model.DriverLicenseIssuedDate = driverLicenseIssuedDate == DateTime.MinValue ? (DateTime?)null : driverLicenseIssuedDate; if (!model.Email.IsValidEmail()) { model.AddModelError(x => x.Email, "Message.NoFutureDate", string.Format("{0} not a valid format.", model.GetDisplayName(x => x.DriverLicenseIssuedDateBS))); } if (model.HasError) { return; } if (!model.Validate()) { return; } var entity = employeeRepository.GetById(model.Id); entity.Name = model.Name; entity.FullNameNP = model.FullNameNP; entity.DateOfBirth = model.DateOfBirth; entity.Gender = model.Gender; entity.AppointmentDate = model.AppointmentDate; entity.DateTo20YrsofServiceDuration = model.DateTo20YrsofServiceDuration; entity.DateTo58YrsOld = model.DateTo58YrsOld; entity.FatherName = model.FatherName; entity.MotherName = model.MotherName; entity.GrandFatherName = model.GrandFatherName; entity.SectionId = model.SectionId; entity.DesignationId = model.DesignationId; entity.HomeTelephone = model.HomeTelephone; entity.OfficeTelephone = model.OfficeTelephone; entity.TelExtenstionNumber = model.TelExtenstionNumber; entity.Mobile = model.Mobile; entity.Email = model.Email; entity.PANNumber = model.PANNumber; entity.CitizenshipNumber = model.CitizenshipNumber; //entity.CitizenshipIssuedDistrictId = model.CitizenshipIssuedDistrictId; entity.CitizenshipIssuedDate = model.CitizenshipIssuedDate; entity.PassportNumber = model.PassportNumber; entity.PassportIssuedDate = model.PassportIssuedDate; entity.DriverLicenseNumber = model.DriverLicenseNumber; entity.DriverLicenseIssuedDate = model.DriverLicenseIssuedDate; entity.MaritalStatus = model.MaritalStatus; entity.SupervisorId = model.SupervisorId; entity.EmployeeType = model.EmployeeType; entity.EmployeeStatus = model.EmployeeStatus; employeeRepository.Update(entity); if (model.Id == 0) { model.Message = localizationService.GetLocalizedText("Message.SavedSuccessfully", defaultText: "Saved succeeded."); } else { model.Message = localizationService.GetLocalizedText("Message.UpdatedSuccessfully", defaultText: "Update succeeded."); } }, model); return(model); }
public ItemUnitViewModel SaveItemUnit(ItemUnitViewModel model) { exceptionService.Execute((m) => { if (itemUnitRepository.Table.Any(x => x.Name == model.Name && x.Id != model.Id)) { model.AddModelError(x => x.Name, "Error.DuplicateValue", "Item unit already exists by this name."); } if (model.HasError) { return; } if (!model.Validate()) { return; } var entity = new ItemUnit(); if (model.Id > 0) { entity = itemUnitRepository.GetById(model.Id); entity.Name = model.Name; entity.Code = model.Code; entity.DisplayOrder = model.DisplayOrder; itemUnitRepository.Update(entity); } else { entity = AutomapperConfig.Mapper.Map <ItemUnit>(model); itemUnitRepository.Insert(entity); } if (model.Id == 0) { model.Message = localizationService.GetLocalizedText("Message.ItemUnitSavedSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Item Unit saved succeeded."); } else { model.Message = localizationService.GetLocalizedText("Message.ItemUnitUpdatedSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Item Unit update succeeded."); } }, model); return(model); }