Пример #1
0
        /// <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));
        }
Пример #2
0
        public IEnumerable <IServicePackageTag> GetPackageTags(ServiceRequestAction action)
        {
            List <IServicePackageTag> tags = new List <IServicePackageTag>();

            switch (action)
            {
            case ServiceRequestAction.New:
                if (NewPackage != null)
                {
                    if (NewPackage.ServiceOptionCategoryTags != null)
                    {
                        tags.AddRange(from o in NewPackage.ServiceOptionCategoryTags select o);
                    }
                    if (NewPackage.ServiceTags != null)
                    {
                        tags.AddRange(from o in NewPackage.ServiceTags select o);
                    }
                    return(tags.OrderBy(t => t.Order));
                }
                return(null);

            case ServiceRequestAction.Change:
                if (ChangePackage != null)
                {
                    if (ChangePackage.ServiceOptionCategoryTags != null)
                    {
                        tags.AddRange(from o in ChangePackage.ServiceOptionCategoryTags select o);
                    }
                    if (ChangePackage.ServiceTags != null)
                    {
                        tags.AddRange(from o in ChangePackage.ServiceTags select o);
                    }
                    return(tags.OrderBy(t => t.Order));
                }
                return(null);

            case ServiceRequestAction.Remove:
                if (RemovePackage != null)
                {
                    if (RemovePackage.ServiceOptionCategoryTags != null)
                    {
                        tags.AddRange(from o in RemovePackage.ServiceOptionCategoryTags select o);
                    }
                    if (RemovePackage.ServiceTags != null)
                    {
                        tags.AddRange(from o in RemovePackage.ServiceTags select o);
                    }
                    return(tags.OrderBy(t => t.Order));
                }
                return(null);
            }

            return(null);
        }
Пример #3
0
        /// <summary>
        /// Retrieves the service packages that the service option id exists in
        /// </summary>
        /// <param name="performingUserId"></param>
        /// <param name="serviceOptionId"></param>
        /// <returns></returns>
        public IEnumerable <IServiceRequestPackageDto> GetServiceRequestPackagesForServiceOption(int performingUserId, int serviceOptionId, ServiceRequestAction action)
        {
            using (var context = new PrometheusContext())
            {
                var option = context.ServiceOptions.Find(serviceOptionId);
                if (option == null)
                {
                    throw new InvalidOperationException(string.Format("Service Option with ID {0} does not exist. Cannot retrieve service package with option identifier {0}.", serviceOptionId));
                }

                //All packages where the service option exists in the first category of the package
                // OR the service option exists in the first service of the package
                var packages = context.ServiceRequestPackages.Where(
                    x => x.Action == action &&
                    (x.ServiceOptionCategoryTags.Any(
                         y => y.Order == 1 && y.ServiceOptionCategory.ServiceOptions.Any(
                             z => z.Id == serviceOptionId)) ||
                     x.ServiceTags.Any(
                         y => y.Order == 1 && y.Service.ServiceOptionCategories.Any(
                             z => z.Id == serviceOptionId))));
                //Sweet baby jesus

                if (!packages.Any())
                {
                    throw new InvalidOperationException(string.Format("Service Request Package with Service Option ID {0} does not exist.", serviceOptionId));
                }

                foreach (var package in packages)
                {
                    yield return(ManualMapper.MapServiceRequestPackageToDto(package));
                }
            }
        }
Пример #4
0
 /// <summary>
 /// deal with the nullable int id
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="portfolioService"></param>
 /// <param name="serviceOptionId"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 public static IServiceRequestPackageDto GetPackage(int userId, IPortfolioService portfolioService, int?serviceOptionId, ServiceRequestAction action) //overload
 {
     if (serviceOptionId.HasValue)                                                                                                                    //invalid input
     {
         return(GetPackage(userId, portfolioService, serviceOptionId.Value, action));
     }
     throw new Exception("Cannot retrieve package, Invalid Service Option parameter");                               //you have reached a dangerous place
 }
Пример #5
0
        /// <summary>
        /// Returns a Service Package for the option if it exists or creates a new one for it and it's id
        /// </summary>
        /// <param name="performingUserId"></param>
        /// <param name="portfolioService"></param>
        /// <param name="optionId"></param>
        /// <param name="action">Add or Remove</param>
        /// <returns></returns>
        public static IServiceRequestPackageDto GetPackage(int performingUserId, IPortfolioService portfolioService, int optionId, ServiceRequestAction action)
        {
            IServiceRequestPackageDto package = null;

            try
            {
                package = portfolioService.GetServiceRequestPackagesForServiceOption(performingUserId, optionId, action).FirstOrDefault();
            }
            catch (Exception) { /* situation is dealt with below */ }

            return(package);
        }
Пример #6
0
 /// <summary>
 /// Retrieves the service packages that the service option id exists in
 /// </summary>
 /// <param name="performingUserId"></param>
 /// <param name="serviceOptionId"></param>
 /// <returns></returns>
 public IEnumerable <IServiceRequestPackageDto> GetServiceRequestPackagesForServiceOption(int performingUserId, int serviceOptionId, ServiceRequestAction action)
 {
     return(_serviceRequestPackageController.GetServiceRequestPackagesForServiceOption(performingUserId, serviceOptionId, action));
 }
 public ServiceRequestMessage(ServiceRequestAction action)
 {
     this.Action = action;
 }