public DataSourceResult ListCIT(ServiceRequestModel <KendoDataRequest> kendoDataRequest) { var loginBranch = kendoDataRequest.LoginInfo.LoginUserBranch; if (loginBranch == null) { throw new ArgumentNullException($"Only BOIC can view the list.", innerException: null); } kendoDataRequest.Model.DataExtensions = new List <DataExtension>() { new DataExtension() { Field = "CreatedDate", FieldType = typeof(DateTime) } }; var queryable = _genericUnitOfWork.GetRepository <CIT, Guid>() .GetAll(); queryable = queryable.Where(c => c.CITBooking.Branch.Id == loginBranch.Id); return(queryable.ToDataSourceResult <CIT, CITListViewModel>(kendoDataRequest.Model, new Sort() { Field = "CITId", Dir = "asc" })); }
public ServiceRequestModel GenerateEditViewModel(EducationSecurityPrincipal user, int requestId) { var serviceRequest = ServiceRequestRepository.Items. Include(s => s.Priority). Include(s => s.Subject). Include(s => s.ServiceType). Include(s => s.Student.ApprovedProviders). Include(s => s.Student.School.UserRoles). Include("Student.StudentAssignedOfferings.ServiceOffering"). Include("Student.StudentAssignedOfferings.ServiceOffering.Provider"). Include(s => s.FulfillmentDetails). Include(s => s.CreatingUser). Include(s => s.LastModifyingUser). SingleOrDefault(s => s.Id == requestId); if (serviceRequest == null) { throw new EntityNotFoundException("Specified Service Request does not exist."); } IPermission permission = PermissionFactory.Current.Create("EditRequest", serviceRequest); permission.GrantAccess(user); ServiceRequestModel viewModel = new ServiceRequestModel(); viewModel.CopyFrom(serviceRequest); PopulateViewModel(viewModel); return(viewModel); }
public void UpdateParttimerSalary(ServiceRequestModel <ParttimerSalaryViewModel> serviceRequestModel) { var employee = _genericUnitOfWork.GetRepository <ParttimerEmployee, Guid>() .GetAll() .SingleOrDefault(c => c.Id == serviceRequestModel.Model.ParttimerEmployeeId); if (employee != null) { if (employee.JoinedDate.Year > serviceRequestModel.Model.SalaryYear && employee.JoinedDate.Month > serviceRequestModel.Model.SalaryMonth) { throw new ArgumentNullException($"Join date is greater than salary date", innerException: null); } } var repo = _genericUnitOfWork.GetRepository <ParttimerSalary, Guid>(); var salaryExists = repo.GetAll().Any(c => c.ParttimerEmployeeId == serviceRequestModel.Model.ParttimerEmployeeId && c.SalaryYear == serviceRequestModel.Model.SalaryYear && c.SalaryMonth == serviceRequestModel.Model.SalaryMonth && c.Id != serviceRequestModel.Model.Id); if (salaryExists) { throw new ArgumentNullException($"Parttimer salary with Year '{serviceRequestModel.Model.SalaryYear}' and Month '{serviceRequestModel.Model.SalaryMonth}' already exists in the system", innerException: null); } var entity = repo.GetById(serviceRequestModel.Model.Id); var mapped = _objectMapper.Map(serviceRequestModel.Model, entity); repo.Update(mapped); _genericUnitOfWork.SaveChanges(); }
public void AddAccessCash(ServiceRequestModel <AccessCashViewModel> serviceRequestModel) { var loginBranch = serviceRequestModel.LoginInfo.LoginUserBranch; if (loginBranch == null) { throw new ArgumentNullException($"Only BOIC can book the CIT.", innerException: null); } var repo = _genericUnitOfWork.GetRepository <AccessCash, Guid>(); var mapped = _mapper.Map <AccessCashViewModel, AccessCash>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.CreatedDate = GeneralService.CurrentDate; mapped.BranchId = loginBranch.Id; repo.Add(mapped); // Sending mail to boas execuitives _genericUnitOfWork.SaveChanges(); }
public void AddITCategory(ServiceRequestModel <ITCategoryViewModel> serviceRequestModel) { var mapped = _mapper.Map <ITCategoryViewModel, IncidentCategory>(serviceRequestModel.Model); _genericUnitOfWork.GetRepository <IncidentCategory, int>().Add(mapped); _genericUnitOfWork.SaveChanges(); }
public void GivenValidViewModel_AndUserIsDataAdmin_WhenEdit_ThenEditDoesNotThrowException() { ServiceRequest newRequestToEdit = CreateServiceRequestInDatabase(2, 2); ServiceRequestModel viewModel = new ServiceRequestModel { Id = newRequestToEdit.Id, SelectedPriorityId = newRequestToEdit.PriorityId, SelectedServiceTypeId = newRequestToEdit.ServiceTypeId, SelectedSubjectId = newRequestToEdit.SubjectId, StudentIds = new int[] { newRequestToEdit.StudentId }, FulfillmentNotes = "blah" }; Target.Edit(User, viewModel); }
public void AddStandardTiming(ServiceRequestModel <StandardTimingViewModel> serviceRequestModel) { var mapped = _mapper.Map <StandardTimingViewModel, StandardTiming>(serviceRequestModel.Model); _genericUnitOfWork.GetRepository <StandardTiming, int>().Add(mapped); _genericUnitOfWork.SaveChanges(); }
public void Create(EducationSecurityPrincipal user, ServiceRequestModel viewModel) { if (user == null) { throw new ArgumentNullException("user"); } if (viewModel == null) { throw new ArgumentNullException("viewModel"); } IPermission permission = PermissionFactory.Current.Create("CreateServiceRequest", StudentRepository.Items.Include(s => s.School.UserRoles).Where(s => viewModel.StudentIds.Contains(s.Id))); permission.GrantAccess(user); List <int> studentIds = viewModel.StudentIds.ToList(); foreach (int studentId in studentIds) { ServiceRequest request = new ServiceRequest(); viewModel.CopyTo(request); request.StudentId = studentId; request.CreatingUser = user.Identity.User; request.CreatingUserId = user.Identity.User.Id; CreateFulfillmentDetail(request, user, viewModel); ServiceRequestRepository.Add(request); } RepositoryContainer.Save(); }
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 DataSourceResult ListIncident(ServiceRequestModel <KendoDataRequest> kendoDataRequest) { kendoDataRequest.Model.DataExtensions = new List <DataExtension>() { new DataExtension() { Field = "IncidentCategory", ActualField = "IncidentCategory.Name" }, new DataExtension() { Field = "Branch", ActualField = "Branch.Name" }, new DataExtension() { Field = "UrgencyType", FieldType = typeof(UrgencyType) }, new DataExtension() { Field = "IncidentType", FieldType = typeof(IncidentType) }, new DataExtension() { Field = "IncidentStatus", FieldType = typeof(IncidentStatus) } }; return(_genericUnitOfWork.GetRepository <Incident, Guid>().GetAll().Where(x => x.ReportedById == kendoDataRequest.CurrentUserId).ToDataSourceResult <Incident, IncidentListViewModel>(kendoDataRequest.Model, new Sort() { Field = "CreatedDate", Dir = "desc" })); }
public void UpdateIncidentReponse(ServiceRequestModel <IncidentResponseViewModel> serviceRequestModel) { var repo = _genericUnitOfWork.GetRepository <Incident, Guid>(); var data = repo.GetById(serviceRequestModel.Model.Id); var mapped = _mapper.Map(serviceRequestModel.Model, data); mapped.IncidentStatus = IncidentStatus.Resolved; var TimeByPriority = GetStandardTimingByPriority((int)data.UrgencyType, (int)data.IncidentType); TimeSpan standaredTime = TimeSpan.Parse(TimeByPriority); if (data.AssignedDate != null) { TimeSpan difference = Convert.ToDateTime(serviceRequestModel.Model.ResolvedDate) - data.AssignedDate.Value; mapped.Variance = Math.Round(Convert.ToDouble((standaredTime - difference).TotalHours), 2).ToString(); } repo.Update(mapped); _genericUnitOfWork.SaveChanges(); var notificationData = _genericUnitOfWork.GetRepository <Incident, Guid>().GetAll().Include("Branch").Include("IncidentCategory").SingleOrDefault(x => x.Id == mapped.Id); var notificationViewModel = _mapper.Map <Incident, ITNotificationViewModel>(notificationData); if (data.ReportedById != null) { SendResolvedIncidentServiceProcessingEmail(data.ReportedById.Value, notificationViewModel); } }
public async Task <IActionResult> SOPreviewEdit(ServiceRequestModel model) { if (ModelState.IsValid) { if (model.RequestId == null) { return(RedirectToAction("ServiceRequests")); } var soorder = await _workorderService.GetServiceRequestById((int)model.RequestId); if (soorder == null) { return(RedirectToAction("ServiceRequests")); } soorder = await _workorderService.PrepareUpdateServiceRequestModel(soorder, model); SuccessNotification("The service request data has been updated successfully."); return(RedirectToAction("SOPreviewEdit", "WorkOrders", new { RequestID = model.RequestId })); } return(View(model)); }
public void AddInternetBackUpTesting(ServiceRequestModel <InternetBackupTestingViewModel> serviceRequestModel) { var repo = _genericUnitOfWork.GetRepository <InternetBackUpTesting, Guid>(); var loginBranchId = serviceRequestModel.LoginInfo.LoginUserBranches.Select(c => c.Id).FirstOrDefault(); var internetBackUpTestExist = repo.GetAll().Any(x => x.StartedDate.Month == GeneralService.CurrentDate.Month && x.StartedDate.Year == GeneralService.CurrentDate.Year && x.BranchId == loginBranchId); if (internetBackUpTestExist) { throw new ArgumentNullException($"Internet backup testing for this month {GeneralService.CurrentDate.ToString("MMMM")} already exists in the system", innerException: null); } var mapped = _mapper.Map <InternetBackupTestingViewModel, InternetBackUpTesting>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.CreatedDate = GeneralService.CurrentDate; if (serviceRequestModel.CurrentUserId != null) { mapped.TestedById = serviceRequestModel.CurrentUserId.Value; } TimeSpan timeDifference = Convert.ToDateTime(serviceRequestModel.Model.FinishedDate) - Convert.ToDateTime(serviceRequestModel.Model.StartedDate); mapped.Duration = timeDifference.TotalMinutes.ToString(); mapped.BranchId = serviceRequestModel.LoginInfo.LoginUserBranches.Select(x => x.Id).FirstOrDefault(); _genericUnitOfWork.GetRepository <InternetBackUpTesting, Guid>().Add(mapped); _genericUnitOfWork.SaveChanges(); var data = _genericUnitOfWork.GetRepository <InternetBackUpTesting, Guid>().GetAll().Include("Branch").SingleOrDefault(x => x.Id == mapped.Id); var notificationViewModel = _mapper.Map <InternetBackUpTesting, ITNotificationViewModel>(data); SendAddInternetBackupTestingProcessingEmail(new Guid(ApplicationConstants.ITHoDRoleId), notificationViewModel); }
public async Task <ServiceResponseModel> AddNewServiceAsync(ServiceRequestModel serviceRequestModel) { var service = _mapper.Map <Service>(serviceRequestModel); var createdService = await _serviceRepository.AddServiceAsync(service); return(_mapper.Map <ServiceResponseModel>(createdService)); }
public async Task <ActionResult> UpdateServiceDetailsAsync(ServiceRequestModel serviceRequestModel) { int id = serviceRequestModel.Id; var service = await _serviceService.UpdateServiceDetailsAsync(serviceRequestModel); return(Ok(service)); }
public override void OnException(HttpActionExecutedContext actionExecutedContext) { try { if (actionExecutedContext.Exception.GetType().Name == "ArgumentNullException") return; var errorLogServiceLog = actionExecutedContext.Request.GetDependencyScope().GetService(typeof(IErrorLogService)) as IErrorLogService; var entity = new ServiceRequestModel<ErrorLogViewModel>() { Model = new ErrorLogViewModel() { Action = actionExecutedContext.ActionContext.ActionDescriptor.ActionName, Data = actionExecutedContext.ActionContext.ActionArguments.First().Value, Entity = actionExecutedContext.ActionContext.ActionArguments.First().Value.GetType().FullName, Message = actionExecutedContext.Exception.Message, InnerException = actionExecutedContext.Exception.InnerException?.Message, ErrorCode = actionExecutedContext.Exception.GetType().Name }, CurrentUserId = HttpContext.Current.User.Identity.IsAuthenticated ? HttpContext.Current.User.Identity.GetUserGuid() : (Guid?)null }; errorLogServiceLog?.Add(entity); } catch (Exception) { // ignored } base.OnException(actionExecutedContext); }
public void AddPurchase(ServiceRequestModel <PurchaseViewModel> serviceRequestModel) { var mapped = _mapper.Map <PurchaseViewModel, Purchase>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.CreatedDate = GeneralService.CurrentDate; mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.Step = 1; mapped.ProcessingStatus = ProcessingStatus.Pending; if (serviceRequestModel.LoginInfo.RoleId == new Guid(ApplicationConstants.AreaAdministratorRoleId) || serviceRequestModel.LoginInfo.RoleId == new Guid(ApplicationConstants.AssistantAreaAdministratorRoleId)) { mapped.BranchId = serviceRequestModel.Model.BranchId.Value; } else { mapped.BranchId = serviceRequestModel.LoginInfo.LoginUserBranches.FirstOrDefault().Id; } _genericUnitOfWork.GetRepository <Purchase, Guid>().Add(mapped); _genericUnitOfWork.SaveChanges(); var emails = _sharedService.GetPurchaseProcessorEmails(mapped.Id); SendEmailToFirstStep(emails, new AdminNotificationViewModel() { Date = mapped.CreatedDate.ToString("dd/MM/yyyy"), Sender = _sharedService.GetUserFullName(mapped.CreatedById), ProcessingType = mapped.ProcessingStatus.ToString(), Category = serviceRequestModel.Model.CategoryName, CategoryItem = serviceRequestModel.Model.CategoryItemName, PurchaseQuotations = serviceRequestModel.Model.Quotations, }); }
public void AddAdminCategoryItem(ServiceRequestModel <AdminCategoryItemViewModel> serviceRequestModel) { var mapped = _mapper.Map <AdminCategoryItemViewModel, CategoryItems>(serviceRequestModel.Model); _genericUnitOfWork.GetRepository <CategoryItems, int>().Add(mapped); _genericUnitOfWork.SaveChanges(); }
public async Task <ServiceResponseModel> UpdateService(ServiceRequestModel serviceRequestModel) { var service = _mapper.Map <Service>(serviceRequestModel); var updatedService = await _serviceRepository.UpdateAsync(service); return(_mapper.Map <ServiceResponseModel>(updatedService)); }
public DataSourceResult ListAssessment(ServiceRequestModel <KendoDataRequest> kendoDataRequest) { kendoDataRequest.Model.DataExtensions = new List <DataExtension>() { new DataExtension() { Field = "BranchName", ActualField = "Branch.Name" }, new DataExtension() { Field = "AssessmentType", FieldType = typeof(AssessmentType) }, new DataExtension() { Field = "AssessmentTypeName", ActualField = "AssessmentType" }, new DataExtension() { Field = "Status", FieldType = typeof(AssessmentStatus) }, new DataExtension() { Field = "StatusName", ActualField = "Status" }, }; return(_genericUnitOfWork.GetRepository <BOCAAssessment, Guid>().GetAll().Where(c => c.AssessorId == kendoDataRequest.CurrentUserId.Value).OrderByDescending(x => x.AssessmentNo).ToDataSourceResult <BOCAAssessment, BOCAAssessmentListViewModel>(kendoDataRequest.Model, new Sort() { Field = "AssessmentNo", Dir = "desc" })); }
public void CreateRecord(ServiceRequestModel request) { request.id = Guid.NewGuid(); var response = _serviceRequestContext.servicerequest.Add(request); _serviceRequestContext.SaveChanges(); }
//for saving service request in db public ActionResult AddRequest(ServiceRequestModel objsr) { if (Session["email"] != null) { string email = (string)Session["email"]; //generating random emailid and adding in the object of sr below Random rnd = new Random(); int idRandom = rnd.Next(10000000, 99999999); // creates a 8 digit random no. objsr.idsr = idRandom.ToString(); bool flag = objsr.saveServiceRequestAPI(objsr, email); ServiceRequestModel objSr1 = new ServiceRequestModel(); if (flag == true) { TempData["message"] = "Service request added successfully"; return(RedirectToAction("addRequest", "View", objSr1)); } else { TempData["message"] = "Oops! Please try again later."; return(RedirectToAction("addRequest", "View", objSr1)); } } else { return(RedirectToAction("Index", "Login")); } }
public void DeleteCrossAssignment(ServiceRequestModel <Guid> serviceRequestModel) { var data = WorkScheduleRepository.GetById(serviceRequestModel.Model); WorkScheduleRepository.Delete(data); _genericUnitOfWork.SaveChanges(); }
public void Create(EducationSecurityPrincipal user, ServiceRequestModel viewModel) { if (user == null) { throw new ArgumentNullException("user"); } if (viewModel == null) { throw new ArgumentNullException("viewModel"); } IPermission permission = PermissionFactory.Current.Create("CreateServiceRequest", StudentRepository.Items.Include(s => s.School.UserRoles).Where(s => viewModel.StudentIds.Contains(s.Id))); permission.GrantAccess(user); List<int> studentIds = viewModel.StudentIds.ToList(); foreach (int studentId in studentIds) { ServiceRequest request = new ServiceRequest(); viewModel.CopyTo(request); request.StudentId = studentId; request.CreatingUser = user.Identity.User; request.CreatingUserId = user.Identity.User.Id; CreateFulfillmentDetail(request, user, viewModel); ServiceRequestRepository.Add(request); } RepositoryContainer.Save(); }
public bool UpdateService(ServiceRequestModel serviceRequestModel) { if (serviceRequestModel == null || serviceRequestModel.ServiceId == Guid.Empty || string.IsNullOrWhiteSpace(serviceRequestModel.Name) || string.IsNullOrWhiteSpace(serviceRequestModel.Version)) { return(false); } try { ServiceModel serviceModel = new ServiceModel() { ServiceId = (Guid)serviceRequestModel.ServiceId, Name = serviceRequestModel.Name, Version = serviceRequestModel.Version }; return(ServiceRepository.UpdateService(serviceModel)); } catch (Exception ex) { Logger.LogFile($"Error updating a Service: {ex.Message}"); } return(false); }
public DataSourceResult ListCITBookingCancel(ServiceRequestModel <KendoDataRequest> kendoDataRequest) { var loginBranch = kendoDataRequest.LoginInfo.LoginUserBranch; if (loginBranch == null) { throw new ArgumentNullException($"Only BOIC can view the list.", innerException: null); } kendoDataRequest.Model.DataExtensions = new List <DataExtension>() { new DataExtension() { Field = "CreatedDate", FieldType = typeof(DateTime) }, new DataExtension() { Field = "CancellationType", FieldType = typeof(CancellationType) } }; return(_genericUnitOfWork.GetRepository <CITBookingCancel, Guid>().GetAll() .ToDataSourceResult <CITBookingCancel, CITBookingCancelListViewModel>(kendoDataRequest.Model, new Sort() { Field = "CITBookingCancelId", Dir = "asc" })); }
public DataSourceResult ListAssessment(ServiceRequestModel <KendoDataRequest> kendoDataRequest) { kendoDataRequest.Model.DataExtensions = new List <DataExtension>() { new DataExtension() { Field = "Agent", ActualField = "Agent.Name" }, new DataExtension() { Field = "AssessmentType", FieldType = typeof(AssessmentType) }, new DataExtension() { Field = "AssessmentTypeName", ActualField = "AssessmentType" }, new DataExtension() { Field = "Status", FieldType = typeof(AssessmentStatus) }, new DataExtension() { Field = "StatusName", ActualField = "Status" }, }; return(AssessmentRepository.GetAll().Where(p => p.CreatedById == kendoDataRequest.CurrentUserId.Value).OrderByDescending(x => x.AssessmentNo).ToDataSourceResult <AOCAAssessment, AocaAssessmentListViewModel>(kendoDataRequest.Model, new Sort() { Field = "AssessmentNo", Dir = "desc" })); }
//private static void AddProperties() //{ // ServiceRequestModel model = new ServiceRequestModel // { // TicketId = "Ticket Id", // ServiceNm = "Service Name", // Staff = "Staff", // Status = "Status", // User = "******" // }; // Add(model); //} public static void Add(ServiceRequestModel requestModel, string spreadSheetId) { // Specifying Column Range for reading... var range = $"{sheet}!A:F"; var valueRange = new ValueRange(); // Data for another Student... var oblist = new List <object>() { requestModel.TicketId, requestModel.FullName, requestModel.ServiceNm, requestModel.Status, requestModel.StaffNm, requestModel.DepartmentNm }; valueRange.Values = new List <IList <object> > { oblist }; // Append the above record... var appendRequest = service.Spreadsheets.Values.Append(valueRange, spreadSheetId, range); appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED; var appendReponse = appendRequest.Execute(); //BatchUpdateValuesRequest requestBody = new BatchUpdateValuesRequest() //{ // ValueInputOption = "USER_ENTERED", // //Data = new List<ValueRange>() { new List<IList<object>> { oblist } } //}; //SpreadsheetsResource.ValuesResource.BatchUpdateRequest request = service.Spreadsheets.Values.BatchUpdate(requestBody, SpreadsheetId); //BatchUpdateValuesResponse response = request.Execute(); }
public IList <ListViewModel> ListBookingCit(ServiceRequestModel <Guid> id, string type) { var loginBranch = id.LoginInfo.LoginUserBranch; if (loginBranch == null) { throw new ArgumentNullException($"Invalid login", innerException: null); } var queryable = _genericUnitOfWork.GetRepository <CITBooking, Guid>().GetAll().Where(c => c.BranchId == loginBranch.Id && TruncateTime(c.CreatedDate) == GeneralService.CurrentDate.Date); if (id.Model == Guid.Empty) { queryable = queryable.Where(c => c.CITBookingCancel == null && c.CIT == null); } else if (type == "cancellation") { queryable = queryable.Where(c => (c.CITBookingCancel != null && c.CITBookingCancel.CITBookingCancelId == id.Model)); } else { queryable = queryable.Where(c => (c.CIT != null && c.CIT.CITId == id.Model)); } var result = queryable.ToList(); return(_mapper.Map <IList <CITBooking>, IList <ListViewModel> >(result)); }
// GET: ServiceRequest/Edit/5 public ActionResult Edit(int?id) { ServiceRequestModel request = new ServiceRequestModel(); InitializePageData(); try { if (!id.HasValue) { DisplayWarningMessage("Looks like, the ID is missing in your request"); return(RedirectToAction("List")); } if (!requestService.Exists(id.Value)) { DisplayWarningMessage($"Sorry, We couldn't find the Service Request with ID: {id.Value}"); return(RedirectToAction("List")); } ServiceRequestDto requestDto = requestService.GetByID(id.Value); request = Mapper.Map <ServiceRequestDto, ServiceRequestModel>(requestDto); } catch (Exception exp) { DisplayReadErrorMessage(exp); } return(View(request)); }
/// <summary> /// Begin a new Service Request /// </summary> /// <param name="id">selected option Id</param> /// <param name="serviceRequestAction"></param> /// <returns></returns> public ActionResult Begin(int id, ServiceRequestAction serviceRequestAction = ServiceRequestAction.New) { ServiceRequestModel model = new ServiceRequestModel { ServiceRequest = new ServiceRequestDto { ServiceOptionId = id }, SelectedAction = serviceRequestAction }; //start new SR model.NewPackage = ServicePackageHelper.GetPackage(UserId, _portfolioService, id, ServiceRequestAction.New); model.ChangePackage = ServicePackageHelper.GetPackage(UserId, _portfolioService, id, ServiceRequestAction.Change); model.RemovePackage = ServicePackageHelper.GetPackage(UserId, _portfolioService, id, ServiceRequestAction.Remove); //default if no package found if (model.NewPackage == null && model.ChangePackage == null && model.RemovePackage == null) { model.SelectedAction = ServiceRequestAction.New; model.NewPackage = ServicePackageHelper.GetPackage(UserId, _portfolioService, id); } //add only package found else if (model.NewPackage != null && model.ChangePackage == null && model.RemovePackage == null) { model.SelectedAction = ServiceRequestAction.New; } //change only package found else if (model.NewPackage == null && model.ChangePackage != null && model.RemovePackage == null) { model.SelectedAction = ServiceRequestAction.Change; } //remove package else if (model.NewPackage == null && model.ChangePackage == null && model.RemovePackage != null) { model.SelectedAction = ServiceRequestAction.Remove; } model.CurrentIndex = -1; /* index for info tab */ return(View("ServiceRequest", model)); }
public bool ServiceRequestDetails(List <ServiceSelectedCatDetails> ServiceRequest) { var userid = User.Identity.GetUserId(); var UserDetails = new AgingInHomeContext().ConsumerProfiles.FirstOrDefault(d => d.UserId == userid); var url = new ServiceRequestModel().SubmitServiceRequest(ServiceRequest, UserDetails); var providercatlistig = ServiceRequest.Select(d => d.catId.ToString()); var listinglist = new ProviderListingModel().GetAllListing() .Where(o => providercatlistig.Contains(o.ProviderCategory1.Id.ToString()) && o.IsApproved == (int)ListingStatus.Accepted).ToList(); //Get service RequestId var RequestId = url.Split(',')[1]; ServiceRequestModel serviceRequestModel = AutoMapper.Mapper.Map <ServiceRequestModel>(UserDetails); serviceRequestModel.Id = Convert.ToInt32(RequestId); serviceRequestModel.Email = UserDetails.AspNetUser.Email; foreach (var providerlisting in listinglist.OrderByDescending(s => s.ProviderListingId).ToList()) { //Get selected date time and best time var getselectedInfo = ServiceRequest.FirstOrDefault(s => s.catId == providerlisting.ProviderCategory1.Id); serviceRequestModel.ServiceDate = Convert.ToDateTime(getselectedInfo.CatserviceDate); serviceRequestModel.BestTime = getselectedInfo.CatBestTime; EmailSender.SendEmailToServiceProvider(providerlisting, serviceRequestModel); break; } return(true); }
public void GivenUserChangedStatusButDidNotFilloutFulfillmentNotes_WhenIPostEdit_ThenAPartialViewIsReturned() { ServiceRequestModel viewModel = new ServiceRequestModel { Id = 1, OriginalStatusId = 1, SelectedStatusId = 2 }; var result = Target.Edit(viewModel) as PartialViewResult; Assert.IsNotNull(result); }
public void GivenUserChangedStatusButDidNotFilloutFulfillmentNotes_WhenIPostEdit_ThenGenerateEditViewModelCalled() { ServiceRequestModel viewModel = new ServiceRequestModel { Id = 1, OriginalStatusId = 1, SelectedStatusId = 2 }; var result = Target.Edit(viewModel) as PartialViewResult; MockLogicManager.AssertWasCalled(m => m.GenerateEditViewModel(User, viewModel.Id)); }
public void GivenValidViewModel_AndUserIsNotAdministrator_AndUserIsNotCreator_WhenDelete_ThenThrowEntityAccessUnauthorizedException() { User nonAdminUserEntity = EducationContext.Users.Where(u => u.UserKey == "Fred").Include("UserRoles.Role").Single(); EducationSecurityPrincipal nonAdminUser = new EducationSecurityPrincipal(nonAdminUserEntity); ServiceRequest newRequestToDelete = CreateServiceRequestInDatabase(2, 3); var viewModel = new ServiceRequestModel { Id = newRequestToDelete.Id, SelectedPriorityId = newRequestToDelete.PriorityId, SelectedServiceTypeId = newRequestToDelete.ServiceTypeId, SelectedSubjectId = newRequestToDelete.SubjectId, StudentIds = new int[] { newRequestToDelete.StudentId } }; Target.ExpectException<EntityAccessUnauthorizedException>(() => Target.Delete(nonAdminUser, viewModel.Id)); }
public void GivenAnInvalidModelState_WhenIPostEdit_ThenAPartialViewIsReturned() { ServiceRequestModel expected = new ServiceRequestModel { Id = 1 }; Target.ModelState.AddModelError("blah", "blah message"); var result = Target.Edit(expected) as PartialViewResult; result.AssertGetViewModel(expected); }
public void GivenViewModelIsGenerated_WhenICreate_ThenAPartialViewIsReturned_AndViewModelIsGenerated() { ServiceRequestModel expected = new ServiceRequestModel(); MockLogicManager.Expect(m => m.GenerateCreateViewModel()).Return(expected); var result = Target.Create() as PartialViewResult; result.AssertGetViewModel(expected); }
public void GivenNewEmptyViewModel_WhenPopulateViewModel_ThenNonePriorityAndSubjectOptionsSelectedByDefault() { ServiceRequestModel viewModel = new ServiceRequestModel(); viewModel.SelectedStatusId = 1; viewModel.StudentIds = new List<int> { 1 }; Target.PopulateViewModel(viewModel); Assert.AreEqual(1, viewModel.SelectedSubjectId); Assert.AreEqual(1, viewModel.SelectedPriorityId); }
public ActionResult Edit(ServiceRequestModel viewModel) { if (ModelState.IsValid) { if (viewModel.OriginalStatusId != viewModel.SelectedStatusId && viewModel.FulfillmentNotes == null) { ModelState.AddModelError(string.Empty, "You must put in Fulfillment Notes if you changed the Status"); viewModel = LogicManager.GenerateEditViewModel((EducationSecurityPrincipal)HttpContext.User, viewModel.Id); return PartialView(viewModel); } LogicManager.Edit((EducationSecurityPrincipal)HttpContext.User, viewModel); return Json(true); } LogicManager.PopulateViewModel(viewModel); return PartialView(viewModel); }
public void GivenModelNotModified_WhenCopyFrom_ThenModelStatelastModifyValuesNull() { ServiceRequest expectedState = new ServiceRequest { PriorityId = 1, SubjectId = 1, FulfillmentDetails = new List<ServiceRequestFulfillment> { new ServiceRequestFulfillment { FulfillmentStatusId = 1 } }, CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" } }; ServiceRequestModel target = new ServiceRequestModel(); target.CopyFrom(expectedState); Assert.IsNull(target.Audit.LastModifiedBy); Assert.IsFalse(target.Audit.LastModifyTime.HasValue); }
public void GivenModelHasAuditData_WhenCopyFrom_ThenModelStateSet() { ServiceRequest expectedState = new ServiceRequest { PriorityId = 1, SubjectId = 1, FulfillmentDetails = new List<ServiceRequestFulfillment> { new ServiceRequestFulfillment { FulfillmentStatusId = 1 } }, CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" }, LastModifyTime = new DateTime(2010, 5, 13), LastModifyingUser = new User { DisplayName = "jimGeorge" } }; ServiceRequestModel target = new ServiceRequestModel(); target.CopyFrom(expectedState); AuditModel actualState = target.Audit; Assert.AreEqual(expectedState.CreateTime, actualState.CreateTime); Assert.AreEqual(expectedState.CreatingUser.DisplayName, actualState.CreatedBy); Assert.AreEqual(expectedState.LastModifyTime, actualState.LastModifyTime); Assert.AreEqual(expectedState.LastModifyingUser.DisplayName, actualState.LastModifiedBy); }
public void WhenEdit_ThenModifyAuditDataSet() { int requestId = 1; var viewModel = new ServiceRequestModel { Id = requestId, SelectedPriorityId = Data.Priorities[3].Id, StudentIds = new List<int> { 1 }, SelectedAssignedOfferingId = 2, SelectedStatusId = 2 }; ServiceRequest request = Repositories.MockServiceRequestRepository.Items.Where(s => s.Id == requestId).SingleOrDefault(); PermissionFactory.Current.Expect(m => m.Create("EditRequest", request)).Return(MockRepository.GenerateMock<IPermission>()); request.FulfillmentDetails = Data.ServiceRequestFulfillments; Target.Edit(User, viewModel); Assert.AreEqual(User.Identity.User, request.LastModifyingUser); Assert.IsTrue(request.LastModifyTime.Value.WithinTimeSpanOf(TimeSpan.FromSeconds(1), DateTime.Now)); }
public void GivenViewModel_WhenPopulateViewModel_ThenOnlyActiveServiceTypesPopulated() { ServiceRequestModel viewModel = new ServiceRequestModel(); viewModel.SelectedStatusId = 1; viewModel.StudentIds = new List<int> { 1 }; Target.PopulateViewModel(viewModel); Assert.IsFalse(viewModel.ServiceTypes.Items.Cast<ServiceType>().Where(s => !s.IsActive).Any()); }
public void GivenViewModelWithStudentInfo_WhenPopulateViewModel_ThenItHasActiveAssignedOfferings() { ServiceRequestModel viewModel = new ServiceRequestModel(); viewModel.SelectedStatusId = 1; viewModel.StudentIds = new List<int> { 3 }; var deactivated = Data.StudentAssignedOfferings.Where(s => !s.IsActive).Select(s => s.Id); Target.PopulateViewModel(viewModel); var ids = viewModel.AssignedOfferings.Select(a => int.Parse(a.Value)); Assert.IsFalse(deactivated.Intersect(ids).Any()); }
public void GivenViewModelWithStudentInfo_AndInactiveAssignedOfferingSelected_WhenPopulateViewModel_ThenItHasActiveAssignedOfferings() { ServiceRequestModel viewModel = new ServiceRequestModel { SelectedAssignedOfferingId = 6 }; viewModel.SelectedStatusId = 1; viewModel.StudentIds = new List<int> { 3 }; var deactivated = Data.StudentAssignedOfferings.Single(s => s.Id == 6); Target.PopulateViewModel(viewModel); var ids = viewModel.AssignedOfferings.Select(a => int.Parse(a.Value)); Assert.IsTrue(ids.Contains(deactivated.Id)); }
public void GivenValidViewModel_WhenCreate_ThenNewRequestHasCurrentTimestamp() { List<int> studentIds = new List<int> { 1, 2, 3 }; var students = Repositories.MockStudentRepository.Items.Where(s => studentIds.Contains(s.Id)); PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("CreateServiceRequest"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock<IPermission>()); ServiceRequest actualAdded = null; ServiceRequestModel toCreate = new ServiceRequestModel { StudentIds = studentIds }; Repositories.MockServiceRequestRepository.Expect(m => m.Add(null)).IgnoreArguments().Do(new Action<ServiceRequest>(s => actualAdded = s)); Target.Create(User, toCreate); Assert.IsNotNull(actualAdded); Assert.AreEqual(DateTime.Now.Ticks / TimeSpan.TicksPerSecond, actualAdded.CreateTime.Ticks / TimeSpan.TicksPerSecond); }
public void GivenValidIds_WhenCreate_ThenAttemptGrantAccess() { IPermission permission = MockRepository.GenerateMock<IPermission>(); List<int> studentIds = new List<int> { 1 }; var students = Repositories.MockStudentRepository.Items.Where(s => studentIds.Contains(s.Id)); PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("CreateServiceRequest"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(permission); ServiceRequestModel toCreate = new ServiceRequestModel { StudentIds = studentIds }; Target.Create(User, toCreate); permission.AssertWasCalled(p => p.GrantAccess(User)); }
public void GivenNewEmptyViewModel_WhenPopulateViewModel_ThenNonePrioritySubjectAndStatusOptionsSelectedByDefaultInList() { ServiceRequestModel viewModel = new ServiceRequestModel(); viewModel.SelectedAssignedOfferingId = 1; viewModel.StudentIds = new List<int> { 1 }; Target.PopulateViewModel(viewModel); Assert.AreEqual(1, viewModel.Subjects.SelectedValue); Assert.AreEqual(1, viewModel.Priorities.SelectedValue); Assert.AreEqual(1, viewModel.AssignedOfferings.SelectedValue); Assert.AreEqual(1, viewModel.Statuses.SelectedValue); }
public void GivenPermissionGrantsAccess_WhenCreate_ThenNewRequestReferencesCreatingUser() { int expected = 323; List<int> studentIds = new List<int> { 1 }; var students = Repositories.MockStudentRepository.Items.Where(s => studentIds.Contains(s.Id)); PermissionFactory.Current.Expect(m => m.Create(Arg.Is<string>("CreateServiceRequest"), Arg<object[]>.Matches(paramsArg => AreStudentListEqual(paramsArg, students)))).Return(MockRepository.GenerateMock<IPermission>()); ServiceRequest actualAdded = null; ServiceRequestModel toCreate = new ServiceRequestModel { StudentIds = studentIds }; Repositories.MockServiceRequestRepository.Expect(m => m.Add(null)).IgnoreArguments().Do(new Action<ServiceRequest>(s => actualAdded = s)); User.Identity.User.Id = expected; Target.Create(User, toCreate); Assert.IsNotNull(actualAdded); Assert.AreEqual(expected, actualAdded.CreatingUserId); }
public ActionResult Create(ServiceRequestModel viewModel) { LogicManager.Create((EducationSecurityPrincipal)HttpContext.User, viewModel); return Json(true); }
public void WhenContruct_ThenDefaultsSet() { Target = new ServiceRequestModel(); Assert.AreEqual(1, Target.SelectedPriorityId); Assert.AreEqual(1, Target.SelectedSubjectId); Assert.AreEqual(1, Target.SelectedStatusId); }
public void InitializeTest() { Target = new ServiceRequestModel(); TestData = new TestData(); }
private void AssertSelectLists(ServiceRequestModel actual) { CollectionAssert.AreEqual(Data.Priorities, actual.Priorities.Items.Cast<Priority>().ToList()); CollectionAssert.AreEqual(Data.ServiceTypes.Where(s => s.IsActive).ToList(), actual.ServiceTypes.Items.Cast<ServiceType>().ToList()); CollectionAssert.AreEqual(Data.Subjects, actual.Subjects.Items.Cast<Subject>().ToList()); }
public void GivenServiceRequestHasInactiveServiceType_WhenPopulateViewModel_ThenServiceTypeShows() { ServiceRequestModel viewModel = new ServiceRequestModel { SelectedServiceTypeId = 6 }; viewModel.SelectedStatusId = 1; viewModel.StudentIds = new List<int> { 1 }; Target.PopulateViewModel(viewModel); Assert.IsTrue(viewModel.ServiceTypes.Items.Cast<ServiceType>().Any(s => s.Id == 6)); }
private void CreateFulfillmentDetail(ServiceRequest model, EducationSecurityPrincipal user, ServiceRequestModel viewModel) { int selectedStatusId = viewModel.SelectedStatusId != 0 ? viewModel.SelectedStatusId : 1; var newDetail = new ServiceRequestFulfillment { FulfilledById = viewModel.SelectedAssignedOfferingId, CreatingUser = user.Identity.User, ServiceRequest = model, FulfillmentStatusId = selectedStatusId, Notes = viewModel.FulfillmentNotes }; if (model.FulfillmentDetails == null) { model.FulfillmentDetails = new List<ServiceRequestFulfillment> { newDetail }; } else { model.FulfillmentDetails.Add(newDetail); } }
public void GivenViewModelHasStudentId_AndStudentAssignedOffering_WhenPopulateViewModel_ThenAssignedOfferingContainsFullName() { int studentId = EducationContext.Students.Where(s => s.StudentAssignedOfferings.Any()).Select(s => s.Id).First(); ServiceRequestModel viewModel = new ServiceRequestModel { StudentIds = new[] { studentId } }; Target.PopulateViewModel(viewModel); using (EducationDataContext verificationContext = new EducationDataContext()) { var expected = verificationContext.Students.Where(s => s.Id == studentId).Select(s => s.StudentAssignedOfferings.FirstOrDefault()).Select(a => new { Provider = a.ServiceOffering.Provider, Program = a.ServiceOffering.Program, ServiceType = a.ServiceOffering.ServiceType }).Single(); StringAssert.Contains(viewModel.AssignedOfferings.First().Text, expected.Program.Name); StringAssert.Contains(viewModel.AssignedOfferings.First().Text, expected.Provider.Name); StringAssert.Contains(viewModel.AssignedOfferings.First().Text, expected.ServiceType.Name); } }
public ServiceRequestModel GenerateEditViewModel(EducationSecurityPrincipal user, int requestId) { var serviceRequest = ServiceRequestRepository.Items. Include(s => s.Priority). Include(s => s.Subject). Include(s => s.ServiceType). Include(s => s.Student.ApprovedProviders). Include(s => s.Student.School.UserRoles). Include("Student.StudentAssignedOfferings.ServiceOffering"). Include("Student.StudentAssignedOfferings.ServiceOffering.Provider"). Include(s => s.FulfillmentDetails). Include(s => s.CreatingUser). Include(s => s.LastModifyingUser). SingleOrDefault(s => s.Id == requestId); if (serviceRequest == null) { throw new EntityNotFoundException("Specified Service Request does not exist."); } IPermission permission = PermissionFactory.Current.Create("EditRequest", serviceRequest); permission.GrantAccess(user); ServiceRequestModel viewModel = new ServiceRequestModel(); viewModel.CopyFrom(serviceRequest); PopulateViewModel(viewModel); return viewModel; }
private void UpdateCurrentFulfillmentDetail(ServiceRequest model, ServiceRequestModel viewModel) { var currentFulfillment = ServiceRequestFulfillmentRepository.Items.OrderByDescending(s => s.CreateTime).FirstOrDefault(s => s.ServiceRequestId == model.Id); if (currentFulfillment != null) { currentFulfillment.FulfilledById = viewModel.SelectedAssignedOfferingId; ServiceRequestFulfillmentRepository.Update(currentFulfillment); } }
public ServiceRequestModel GenerateCreateViewModel() { ServiceRequestModel viewModel = new ServiceRequestModel(); PopulateViewModel(viewModel); viewModel.StudentIds = new List<int>(); return viewModel; }
public void PopulateViewModel(ServiceRequestModel viewModel) { if (viewModel == null) { throw new ArgumentNullException("viewModel"); } viewModel.Priorities = new SelectList(PriorityRepository.Items.OrderBy(p => p.Id), "Id", "Name", viewModel.SelectedPriorityId); viewModel.Subjects = new SelectList(LookupHelper.LoadSubjectList(SubjectRepository), "Id", "Name", viewModel.SelectedSubjectId); viewModel.ServiceTypes = new SelectList(ServiceTypeRepository.Items.Where(s => s.IsActive || viewModel.SelectedServiceTypeId == s.Id), "Id", "Name", viewModel.SelectedServiceTypeId); Student selectedStudent = null; if (viewModel.StudentIds != null) { selectedStudent = StudentRepository.Items. Include("StudentAssignedOfferings.ServiceOffering.Provider"). Include("StudentAssignedOfferings.ServiceOffering.ServiceType"). Include("StudentAssignedOfferings.ServiceOffering.Program"). FirstOrDefault(s => s.Id == viewModel.StudentIds.FirstOrDefault()); } List<StudentAssignedOffering> offerings = new List<StudentAssignedOffering>(); if (selectedStudent != null) { viewModel.AssignedOfferings = new SelectList((from o in selectedStudent.StudentAssignedOfferings.Where(s => s.IsActive || (viewModel.SelectedAssignedOfferingId != null && s.Id == viewModel.SelectedAssignedOfferingId)).ToList() select new { Id = o.Id, Name = o.ServiceOffering.Name }), "Id", "Name", viewModel.SelectedAssignedOfferingId); } else { viewModel.AssignedOfferings = new SelectList(Enumerable.Empty<StudentAssignedOffering>()); } viewModel.Statuses = new SelectList(FulfillmentStatusRepository.Items, "Id", "Name", viewModel.SelectedStatusId); }