Пример #1
0
        /// <summary>
        /// Handle the PPE Types on LEFT (i.e. basic details HWCs submit)
        /// </summary>
        void updateBasicPpeDetails(EditNeedsPost s)
        {
            List <PpeTypes> existingPpeTypes = NeedPpeTypes.SelectToList(p => (PpeTypes)p.PpeTypeId);

            //create new
            List <NeedPpeTypeViewModel> ppeTypesToAdd = s.Request.PpeTypes.WhereToList(p => p.Selected && !existingPpeTypes.Contains(p.Type));

            foreach (NeedPpeTypeViewModel needPpeTypeViewModel in ppeTypesToAdd)
            {
                NeedPpeType ppeTypeToAdd = NeedPpeType.Create_FromViewModel(needPpeTypeViewModel, this);
                NeedPpeTypes.Add(ppeTypeToAdd);
            }

            //remove deselected
            List <NeedPpeTypeViewModel> ppeTypesToRemove = s.Request.PpeTypes.WhereToList(p => !p.Selected && existingPpeTypes.Contains(p.Type));

            foreach (NeedPpeTypeViewModel needPpeTypeViewModel in ppeTypesToRemove)
            {
                NeedPpeType typeToRemove = NeedPpeTypes.Single(p => p.PpeTypeId == (byte)needPpeTypeViewModel.Type);
                NeedPpeTypes.Remove(typeToRemove);
            }

            //edit rest (existing)
            List <NeedPpeTypeViewModel> ppeTypesToModify = s.Request.PpeTypes.WhereToList(p => p.Selected && existingPpeTypes.Contains(p.Type));

            foreach (NeedPpeTypeViewModel needPpeTypeViewModel in ppeTypesToModify)
            {
                NeedPpeType needExisting = NeedPpeTypes.SingleOrDefault(p => p.PpeTypeId == (byte)needPpeTypeViewModel.Type);
                needExisting?.Modify(needPpeTypeViewModel);                 //works??
            }
        }
        /// <summary>
        /// For Inserts
        /// </summary>
        public static Need CreateFromViewModel(NeedsViewModel s)
        {
            Need respVal = new Need
            {
                PublishAnonymously = s.PublishAnonymously,
                Timestamp          = DateTimeOffset.Now,          //N.B for inserts
                StatusId           = (int)PostStatus.UnderReview, //N.B for inserts
                ContactName        = s.ContactName ?? "",
                JobTitle           = s.JobTitle,
                Email            = s.Email,
                PhoneNumber      = s.PhoneNumber,
                OrganisationName = s.OrganisationName,
                Department       = s.Department,
                OrgTypeId        = (int)s.OrgType,
                OrgTypeOther     = s.OrgTypeOther,
                TownOrCity       = s.TownOrCity,
                AddressLineOne   = s.AddressLineOne,
                AddressLineTwo   = s.AddressLineTwo,
                Postcode         = s.Postcode,
                TellUsMore       = s.TellUsMore,
            };

            respVal.NeedPpeTypes = s.PpeTypes.Where(nt => nt.Selected).Select(nt => NeedPpeType.Create_FromViewModel(nt, respVal)).ToList();
            return(respVal);
        }
Пример #3
0
 /// <summary>
 /// Handle the Needs Matching data ON RIGHT (i.e. Admin details such as PPE Status and Suppliers etc)
 /// mod those that are in post, and already exist
 /// </summary>
 void updatePpeMatchingDetails(EditNeedsPost s)
 {
     foreach (NeedsMatchData needsMatchData in s.NeedsMatching)
     {
         NeedPpeType needExisting = NeedPpeTypes.SingleOrDefault(p => p.PpeTypeId == (byte)needsMatchData.PpeType);
         needExisting?.Modify(needsMatchData);
     }
 }
Пример #4
0
        static List <NeedPpeType> extractNeedsPpeType(NeedsPost post, Need newNeed)
        {
            List <NeedPpeType> ppeList = new List <NeedPpeType>();

            foreach (string ppe in post.PpeTypes)
            {
                NeedPpeType needsPpe = new NeedPpeType();

                if (Enum.TryParse(ppe, out PpeTypes ppeType)) //N.B. won't work
                {
                    needsPpe.PpeTypeId = (byte)ppeType;
                    if (ppeType == PpeTypes.FFP1RespiratorMasks) //only add the daily shortage if ppe is ffp1
                    {
                        needsPpe.DailyShortage        = post.FFP1DailyShortage;
                        needsPpe.DailyShortageForWhom = post.FFP1DailyDetails;
                    }

                    if (ppeType == PpeTypes.Other)
                    {
                        Debugger.Break();
                        needsPpe.PpeTypeOther = post.OtherPpeTypes; //only add other if ppetype is other
                    }
                }
                else //fallback in case some ppe doesn't match our enums
                {
                    Debugger.Break();
                    needsPpe.PpeTypeId    = (int)PpeTypes.Other;
                    needsPpe.PpeTypeOther = post.OtherPpeTypes;
                }

                needsPpe.StatusId = (int)PpeStatus.New;
                ppeList.Add(needsPpe);
            }

            return(ppeList);
        }