public async Task <IHttpActionResult> ForgetPassword(string email) { var user = await UserManager.FindByEmailAsync(email); if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { return(Ok()); } var uservm = _mapper.Map <User, UserViewModel>(user); await UserManager.SendPasswordResetEmail(uservm); return(Ok()); }
public void AddReliefStaff(ServiceRequestModel <ReliefStaffViewModel> serviceRequestModel) { var mapped = _objectMapper.Map <ReliefStaffViewModel, ReliefStaff>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); _genericUnitOfWork.GetRepository <ReliefStaff, Guid>().Add(mapped); _genericUnitOfWork.SaveChanges(); }
public bool AddActivityApplicationLog(ServiceRequestModel <ApplicationLogViewModel> serviceModel) { try { var mappedData = _objectMapper.Map <ApplicationLogViewModel, ApplicationLog>(serviceModel.Model); mappedData.Date = GeneralService.CurrentDate; mappedData.LogType = LogType.Activity; mappedData.IpAddress = GeneralService.ClientIpFromHeader; mappedData.UserId = serviceModel.CurrentUserId; _genericUnitOfWork.GetRepository <ApplicationLog, int>().Add(mappedData); _genericUnitOfWork.SaveChanges(); return(true); } catch { return(false); } }
public void AddBudgetLimit(ServiceRequestModel <BudgetLimitViewModel> serviceRequestModel) { var repo = _genericUnitOfWork.GetRepository <BudgetLimit, Guid>(); var budgetLimit = repo.GetAll().Any(c => c.BranchId == serviceRequestModel.Model.BranchId && c.ExpensesTypeId == serviceRequestModel.Model.ExpensesTypeId); if (budgetLimit) { throw new ArgumentNullException("Selected expenses type is already exists in selected branch", innerException: null); } var mapped = _objectMapper.Map <BudgetLimitViewModel, BudgetLimit>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); repo.Add(mapped); _genericUnitOfWork.SaveChanges(); }
public void AddParttimerEmployee(ServiceRequestModel <ParttimerEmployeeViewModel> serviceRequestModel) { var mapped = _objectMapper.Map <ParttimerEmployeeViewModel, ParttimerEmployee>(serviceRequestModel.Model); mapped.BranchId = serviceRequestModel.LoginInfo.LoginUserBranches.SingleOrDefault().Id; mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.Id = Guid.NewGuid(); _genericUnitOfWork.GetRepository <ParttimerEmployee, Guid>().Add(mapped); _genericUnitOfWork.SaveChanges(); }
public bool Add(ServiceRequestModel <ErrorLogViewModel> serviceModel) { try { var mappedData = _objectMapper.Map <ErrorLogViewModel, ErrorLog>(serviceModel.Model); mappedData.Date = GeneralService.CurrentDate; mappedData.IpAddress = GeneralService.ClientIpFromHeader; mappedData.UserId = serviceModel.CurrentUserId; _genericUnitOfWork.GetRepository <ErrorLog, int>().Add(mappedData); return(true); } catch { return(false); } }
public WorkScheduleViewModel AddWorkSchedule(ServiceRequestModel <WorkScheduleViewModel> serviceRequestModel) { var repo = _genericUnitOfWork.GetRepository <WorkSchedule, Guid>(); var mapped = _mapper.Map <WorkScheduleViewModel, WorkSchedule>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.PostedById = serviceRequestModel.CurrentUserId.Value; var selected = mapped.Date.Date; mapped.WorkScheduleType = WorkScheduleType.Others; mapped.CreatedDate = GeneralService.CurrentDate; var offDayExists = repo.GetAll().Where(c => c.UserId == serviceRequestModel.Model.UserId && System.Data.Entity.DbFunctions.TruncateTime(c.Date) == selected); if (serviceRequestModel.Model.OffDay && offDayExists.Any()) { throw new ArgumentNullException($"Day Off and Other Schedule are not allowed in same date.", innerException: null); } if (!serviceRequestModel.Model.OffDay && offDayExists.Any(c => c.OffDay)) { throw new ArgumentNullException($"Day Off for the selected date is already there in the system", innerException: null); } repo.Add(mapped); serviceRequestModel.Model.Id = mapped.Id; /* if (serviceRequestModel.Model.WorkStatus != null) * { * var mappedStatus = _mapper.Map<WorkStatusViewModel, WorkStatus>(serviceRequestModel.Model.WorkStatus); * mappedStatus.WorkScheduleId = mapped.Id; * _workStatusRepository.Add(mappedStatus); * serviceRequestModel.Model.WorkStatus.WorkScheduleId = mapped.Id; * } */ _genericUnitOfWork.SaveChanges(); var logModel = new ServiceRequestModel <ApplicationLogViewModel>() { Model = new ApplicationLogViewModel() { Action = System.Reflection.MethodBase.GetCurrentMethod().Name, Data = mapped, Entity = "WorkSchedule" }, CurrentUserId = serviceRequestModel.CurrentUserId }; _applicationLogService.AddActivityApplicationLog(logModel); return(serviceRequestModel.Model); }
public BOCAAssessmentViewModel AddBOCAAssessment(ServiceRequestModel <BOCAAssessmentViewModel> serviceRequestModel) { DateTime assessmentDate; DateTime.TryParse(serviceRequestModel.Model.Date, out assessmentDate); var monthStartDate = assessmentDate.FirstDayOfMonth(); var monthEndDate = assessmentDate.LastDayOfMonth(); if (assessmentDate.Date > GeneralService.CurrentDate.Date) { throw new ArgumentNullException($"The assessment date cannot be in future.", innerException: null); } var assessmentExists = AssessmentRepository.GetAll().Any(c => c.BranchId == serviceRequestModel.Model.BranchId && c.Date >= monthStartDate && c.Date <= monthEndDate); if (assessmentExists) { throw new ArgumentNullException($"BOCA Assessment for the month {assessmentDate.ToString(@"MMM\'yy")} already exists in the system", innerException: null); } var branchOicUser = _sharedService.GetBranchOICUser(serviceRequestModel.Model.BranchId); if (branchOicUser == null) { throw new ArgumentNullException($"There is no user assigned with role Branch OIC for the branch.", innerException: null); } var mapped = _mapper.Map <BOCAAssessmentViewModel, BOCAAssessment>(serviceRequestModel.Model); //mapped.Id = Guid.NewGuid(); //it is not required as Id is already populated var branch = _setupService.GetBranch(mapped.BranchId); var branchAbbr = branch != null ? branch.ShortName : string.Empty; if (string.IsNullOrWhiteSpace(branchAbbr)) { throw new ArgumentNullException($"Assessment number could not be generated as Branch Code is not valid", innerException: null); } var nextBocaRunningNo = _sharedService.GetNextRunningNumber(RunningNumberType.BOCA, mapped.Date.Year, branchAbbr); if (nextBocaRunningNo == 0) { throw new ArgumentNullException($"Error while generating the Assessment Number", innerException: null); } mapped.AssessmentNo = $"{"BOCA"}/{mapped.Date.Year}-{branchAbbr}-{nextBocaRunningNo.ToString().PadLeft(3, '0')}"; mapped.AssessorId = serviceRequestModel.LoginInfo.UserId; mapped.BranchOICUserId = branchOicUser.Id; mapped.Status = AssessmentStatus.Open; mapped.CreatedDate = GeneralService.CurrentDate; if (!serviceRequestModel.Model.IsPartialSave) { mapped.Status = serviceRequestModel.Model.ChecklistCriteria.SelectMany(x => x.BOCAChecklist).Where(x => x.CARRRequest != null).Select(x => x.CARRRequest).Any() ? AssessmentStatus.Open : AssessmentStatus.Closed; mapped.IsCompleted = true; } AssessmentRepository.Add(mapped); var carrCount = 0; foreach (var bocaViewModel in serviceRequestModel.Model.ChecklistCriteria.SelectMany(x => x.BOCAChecklist).ToList()) { //bocaViewModel.Id = Guid.NewGuid(); bocaViewModel.BOCAAssessmentId = mapped.Id; var boca = _mapper.Map <BOCAViewModel, BOCA>(bocaViewModel); boca.Attachments = null; BocaRepository.Add(boca); if (bocaViewModel.CARRRequest != null) { var nextCarrRunningNo = 0; if (!serviceRequestModel.Model.IsPartialSave) { nextCarrRunningNo = _sharedService.GetNextRunningNumber(RunningNumberType.CARR, mapped.Date.Year, branchAbbr); } var carrReq = _mapper.Map <CARRRequestViewModel, CARRRequest>(bocaViewModel.CARRRequest); var carrId = Guid.NewGuid(); // response for partial save bocaViewModel.CARRRequest.Id = carrId; carrReq.Id = carrId; carrReq.BOCAId = boca.Id; if (!serviceRequestModel.Model.IsPartialSave) { carrReq.ReferenceNo = $"{"BOCA/CARR"}/{mapped.Date.Year}-{branchAbbr}-{nextCarrRunningNo.ToString().PadLeft(3, '0')}"; } //carrReq.RecommendedReplyDate = mapped.Date.AddDays(14); carrReq.CARRStatus = CARRStatus.Pending; CarrRequestRepository.Add(carrReq); carrCount++; } if (bocaViewModel.Attachments.Any()) { bocaViewModel.Attachments.ForEach(y => { y.Id = Guid.NewGuid(); y.BOCAId = boca.Id; var p = _mapper.Map <BocaAttachmentViewModel, BOCAAttachment>(y); var attachFullName = p.AttachmentFullName.MoveToDestination(serviceRequestModel.Model.HostingEnviromentPath, "BOCA/" + mapped.Id); y.AttachmentFullName = attachFullName; p.AttachmentFullName = attachFullName; AttachmentRepository.Add(p); }); } } _genericUnitOfWork.SaveChanges(); if (serviceRequestModel.Model.IsPartialSave) { serviceRequestModel.Model.AssessmentNo = mapped.AssessmentNo; return(serviceRequestModel.Model); } if (carrCount == 0) { return(new BOCAAssessmentViewModel()); } var bocaNotificationViewModel = new BOCANotificationViewModel { AssessmentNo = mapped.AssessmentNo, CARRRequestCount = carrCount, ToEmail = branchOicUser.Email }; SendCarrRequestedEmailsToBranchOicUser(bocaNotificationViewModel); return(new BOCAAssessmentViewModel()); }
public void AddCITBooking(ServiceRequestModel <CITBookingViewModel> serviceRequestModel) { var loginBranch = serviceRequestModel.LoginInfo.LoginUserBranch; if (loginBranch == null) { throw new ArgumentNullException($"Only BOIC can book the CIT.", innerException: null); } var repo = _genericUnitOfWork.GetRepository <CITBooking, Guid>(); var todayDate = GeneralService.CurrentDate.Date; var today = repo.GetAll().Any(c => TruncateTime(c.CreatedDate) == todayDate && c.BranchId == loginBranch.Id && c.CITBookingCancel == null && c.CIT == null); if (today) { throw new ArgumentNullException($"Please cancel or post cit to do next booking.", innerException: null); } var mapped = _mapper.Map <CITBookingViewModel, CITBooking>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.CreatedDate = GeneralService.CurrentDate; mapped.BranchId = loginBranch.Id; mapped.BookingCode = _sharedService.GenerateNumber(RunningNumberType.CITBooking, mapped.CreatedDate.Year, loginBranch.ShortName, "CIT/Booking/", "yyyy", "MM", 3); repo.Add(mapped); // Sending mail to boas execuitives _genericUnitOfWork.SaveChanges(); }
public void AddExternalAudit(ServiceRequestModel <ExternalAuditViewModel> serviceRequestModel) { var repo = _genericUnitOfWork.GetRepository <ExternalAudit, Guid>(); var mapped = _mapper.Map <ExternalAuditViewModel, ExternalAudit>(serviceRequestModel.Model); var bankExists = repo.GetAll().Any(c => c.Agent.Id == mapped.AgentId && c.Date.Month == mapped.Date.Month && c.Date.Year == mapped.Date.Year); if (bankExists) { throw new ArgumentNullException($"External audit for the selected agent and month is already exists in the system", innerException: null); } mapped.Id = Guid.NewGuid(); mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.CreatedDate = GeneralService.CurrentDate; repo.Add(mapped); _genericUnitOfWork.SaveChanges(); }
public List <UserPageViewModel> ListUserPage(Guid userId) { Guid roleId = _genericUnitOfWork.GetRepository <User, Guid>().GetAll().FirstOrDefault(c => c.Id == userId).Roles.FirstOrDefault().RoleId; var pages = _mapper.Map <List <UserPage>, List <UserPageViewModel> >(_genericUnitOfWork.GetRepository <UserPage, int>().GetAll().Distinct().Where(c => c.RoleId == roleId && c.Page.ShowInView).OrderBy(c => c.Page.DisplayOrder).ToList()); var pageTree = GetChildPages(pages, null); return(pageTree); }
public void AddIncident(ServiceRequestModel <IncidentViewModel> serviceRequestModel) { var mapped = _mapper.Map <IncidentViewModel, Incident>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.CreatedDate = GeneralService.CurrentDate; if (serviceRequestModel.CurrentUserId != null) { mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.ReportedById = serviceRequestModel.CurrentUserId.Value; } mapped.IncidentStatus = IncidentStatus.Pending; mapped.ReportingType = ReportingType.System; mapped.ReportedDate = GeneralService.CurrentDate; mapped.StandardTimeId = _genericUnitOfWork.GetRepository <StandardTiming, int>().GetAll().Where(x => x.PriorityId == (UrgencyType)mapped.UrgencyType && x.IncidentType == (IncidentType)mapped.IncidentType).Select(x => x.Id).FirstOrDefault(); mapped.BranchId = serviceRequestModel.LoginInfo.LoginUserBranches.Select(x => x.Id).FirstOrDefault(); _genericUnitOfWork.GetRepository <Incident, Guid>().Add(mapped); //Email To ITHoD _genericUnitOfWork.SaveChanges(); var data = _genericUnitOfWork.GetRepository <Incident, Guid>().GetAll().Include("Branch").Include("IncidentCategory").SingleOrDefault(x => x.Id == mapped.Id); var notificationViewModel = _mapper.Map <Incident, ITNotificationViewModel>(data); SendAddIncidentServiceProcessingEmail(new Guid(ApplicationConstants.ITHoDRoleId), notificationViewModel); }
public void AddInsurance(ServiceRequestModel <InsuranceViewModel> serviceRequestModel) { var mapped = _mapper.Map <InsuranceViewModel, Insurance>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.CreatedDate = GeneralService.CurrentDate; _genericUnitOfWork.GetRepository <Insurance, Guid>().Add(mapped); _genericUnitOfWork.SaveChanges(); }