public static SupplyM ProjectFromDb(Supplier s) { SupplyM respVal = new SupplyM(); respVal.Id = s.Id; respVal.DateTime = s.Timestamp.UtcDateTime; respVal.Postcode = s.Postcode; respVal.Latitude = s.Latitude; respVal.Longitude = s.Longitude; respVal.Organisation = s.Name; respVal.Description = s.Description; // respVal.Website = s.Website; // respVal.CapacityNotes = s.CapacityNotes; List <PpeTypes> ppeTypesList = s.SupplierPpeTypes.SelectToList(p => (PpeTypes)p.PpeTypeId); respVal.PpeTypes = ppeTypesList.SelectToList(p => p.GetText()); if (ppeTypesList.Contains(Db.PpeTypes.Other)) { SupplierPpeType otherDetails = s.SupplierPpeTypes.Single(p => p.PpeTypeId == (byte)Db.PpeTypes.Other); respVal.OtherPpeTypes = otherDetails.PpeTypeOther; } return(respVal); }
public static SupplierPpeTypeModel FromEntity(SupplierPpeType s) { return(new SupplierPpeTypeModel { CapacityPerWeek = s.CapacityPerWeek, CostType = (CostTypes)s.CostTypeId, CostTypeOther = s.CostTypeOther, CurrentStock = s.CurrentStock, LeadTimeInDays = s.LeadTimeInDays, MeetsRegulations = (MeetsRegulations)s.MeetsRegulatoryRequirementsId, Type = (PpeTypes)s.PpeTypeId, Selected = true }); }
public IActionResult RegisterSupplies([FromServices] DataContext dataContext, SuppliesViewModel data) { SimpleNotifier noty = notifier(); if (ModelState.IsValid) { Supplier supplier = Supplier.CreateFromViewModel(data); dataContext.Suppliers.Add(supplier); List <SupplierPpeType> supplierPpeTypes = data.PpeTypes.Where(st => st.Selected).Select(st => SupplierPpeType.Create_FromViewModel(st, supplier)).ToList(); supplierPpeTypes.ForEach(st => dataContext.SupplierPpeTypes.Add(st)); dataContext.SaveChanges(currentUserName); noty.AddMessage(MsgTypes.Success, "Thanks you have been added to the database, we will be in contact in due course"); return(Redirect("/")); } else { noty.AddMessage(MsgTypes.Warning, "Problems saving details, please fix and try again"); return(View(data)); } }