public static Need FromWebNeed(WebNeed s) { Need respVal = new Need { UshahidiId = s.UshahidiId, Timestamp = s.Timestamp, StatusId = (int)PostStatus.Published, //always PublishAnonymously = s.PublishAnonymously, ContactName = s.ContactName, //NN JobTitle = s.JobTitle, Email = Settings.DefaultEmail, //Email = s.Email,//no point - empty //TODO:ensure volunteers do this //PhoneNumber = s.PhoneNumber,//no point - empty //TODO:ensure volunteers do this OrganisationName = s.OrganisationName, Department = s.Department, OrgTypeId = s.OrgTypeId, OrgTypeOther = s.OrgTypeOther, TownOrCity = s.TownOrCity, TweetId = s.TweetId, Postcode = s.Postcode, //NN TellUsMore = s.TellUsMore, Latitude = s.Latitude, Longitude = s.Longitude, }; if (respVal.ContactName != null && respVal.ContactName.Length > 100) { Debugger.Break(); } if (respVal.Department != null && respVal.Department.Length > 200) { Debugger.Break(); } if (respVal.Email != null && respVal.Email.Length > 320) { Debugger.Break(); } if (respVal.JobTitle != null && respVal.JobTitle.Length > 100) { Debugger.Break(); } if (respVal.OrgTypeOther != null && respVal.OrgTypeOther.Length > 300) { Debugger.Break(); } if (respVal.OrganisationName != null && respVal.OrganisationName.Length > 200) { Debugger.Break(); } if (respVal.PhoneNumber != null && respVal.PhoneNumber.Length > 100) { Debugger.Break(); } if (respVal.Postcode != null && respVal.Postcode.Length > 8) { Debugger.Break(); } if (respVal.TownOrCity != null && respVal.TownOrCity.Length > 200) { Debugger.Break(); } respVal.NeedPpeTypes = s.NeedPpeTypes.SelectToList(ppe => FromWebNeedPpeType(ppe, respVal)); List <byte> t = s.NeedPpeTypes.GroupBy(g => g.PpeTypeId).Where(g => g.Count() > 1).SelectToList(g => g.Key); if (t.Count > 0) { Debug.WriteLine($"UshahidiId {s.UshahidiId} Need has duplicate PPE types {HtmlHelp.BuildString(t, ", ")}"); respVal = null; } //if(s.UshahidiId == 471) //{ // Debug.WriteLine($"UshahidiId {s.UshahidiId} has an awesome postcode {respVal.Postcode}"); // respVal = null; //} return(respVal); }
public static Supplier FromWebSupply(WebSupply s, string currentUserId) { Supplier respVal = new Supplier { UshahidiId = s.UshahidiId, Timestamp = s.Timestamp, StatusId = (int)PostStatus.Published, //always Name = s.Name, Description = s.Description, SupplierTypeId = s.SupplierTypeId, SupplierTypeOther = s.SupplierTypeOther, //Email = s.Email,//imports from g sheets Website = Urls.GetFullValidHttpUrl(s.Website), //PhoneNumber = s.PhoneNumber,//imports from g sheets //ContactName = s.ContactName,//imports from g sheets Postcode = s.Postcode, //NN TellUsMore = s.TellUsMore, Latitude = s.Latitude, Longitude = s.Longitude, CapacityNotes = s.CapacityNotes }; respVal.SupplierPpeTypes = s.SupplierPpeTypes.SelectToList(ppe => FromWebSupplyPpeType(ppe, respVal)); List <byte> t = s.SupplierPpeTypes.GroupBy(g => g.PpeTypeId).Where(g => g.Count() > 1).SelectToList(g => g.Key); if (t.Count > 0) { Debug.WriteLine($"UshahidiId {s.UshahidiId} Supplier has duplicate PPE types {HtmlHelp.BuildString(t, ", ")}"); respVal = null; } //else //{ // if(!String.IsNullOrWhiteSpace(s.ContactDetailsForNotes)) //TODO:remove when confirmed // { // SupplierNote newNote = new SupplierNote // { // Supplier = respVal, // Note = new Note // { // Timestamp = DateTimeOffset.Now, // UserId = currentUserId, // Text = $"Contact Details From Ushahidi :{Environment.NewLine}{s.ContactDetailsForNotes}", // } // }; // respVal.SupplierNotes.Add(newNote); // } //} return(respVal); }