//public static List<StateId> LoadStateIds() //{ // try // { // using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) // { // List<StateId> results = new List<StateId>(); // dc.tblStateIds.ToList().ForEach(s => results.Add(new StateId // { // Id = s.Id, // Name = s.Name // })); // return results; // } // } // catch (Exception ex) // { // throw ex; // } //} public static UserAddress LoadById(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserAddress UserAddressRow = dc.tblUserAddresses.FirstOrDefault(a => a.Id == id); if (UserAddressRow != null) { return(new UserAddress { Id = UserAddressRow.Id, UserId = UserAddressRow.UserId, Address = UserAddressRow.Address, City = UserAddressRow.City, StateId = UserAddressRow.StateId, StateName = LoadStateById(UserAddressRow.StateId).Name, StateAbbreviation = LoadStateById(UserAddressRow.StateId).Abbreviation, ZipCode = UserAddressRow.ZipCode }); } else { throw new Exception("Row not found..."); } } } catch (Exception ex) { throw ex; } }
public static int Delete(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserAddress deletedrow = dc.tblUserAddresses.FirstOrDefault(a => a.Id == id); if (deletedrow != null) { dc.tblUserAddresses.Remove(deletedrow); return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(UserAddress userAddress) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserAddress updatedrow = dc.tblUserAddresses.FirstOrDefault(a => a.Id == userAddress.Id); if (updatedrow != null) { State newstate = new State(); //newstate.Id = LoadStateByAbbreviation(userAddress.StateAbbreviation).Id; // This is so the user will only need to enter WI. updatedrow.UserId = userAddress.UserId; updatedrow.Address = userAddress.Address; updatedrow.City = userAddress.City; updatedrow.StateId = userAddress.StateId; updatedrow.ZipCode = userAddress.ZipCode; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(Guid id, Guid userid, string address, string city, string stateAbbreviation, string zipcode) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserAddress updatedrow = dc.tblUserAddresses.FirstOrDefault(a => a.Id == id); if (updatedrow != null) { State newstate = new State(); newstate.Id = LoadStateByAbbreviation(stateAbbreviation).Id; // This is so the user will only need to enter WI. updatedrow.UserId = userid; updatedrow.Address = address; updatedrow.City = city; updatedrow.StateId = newstate.Id; updatedrow.ZipCode = zipcode; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static bool Insert(Guid userid, string address, string city, string stateAbbreviation, string zipcode) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { // Make a new row tblUserAddress newrow = new tblUserAddress(); State newstate = new State(); newstate.Id = LoadStateByAbbreviation(stateAbbreviation).Id; // This is so the user will only need to enter WI. // Set the properties newrow.Id = Guid.NewGuid(); newrow.UserId = userid; newrow.Address = address; newrow.City = city; newrow.StateId = newstate.Id; newrow.ZipCode = zipcode; // Do the Insert dc.tblUserAddresses.Add(newrow); // Commit the insert return(Convert.ToBoolean(dc.SaveChanges())); } } catch (Exception ex) { throw ex; } }
public bool SaveDeliveryOption(DeliveryOption deliveryOption) { var oderObj = bringlyEntities.tblOrders .Where(odr => odr.IsDeleted == false && odr.OrderGuid == deliveryOption.OrderGuid).FirstOrDefault(); if (oderObj == null) { return(false); } oderObj.OrderType = (short)deliveryOption.DeliveryType; var orderAddress = bringlyEntities.tblOrderAddresses .Where(z => z.IsDeleted == false && z.FK_OrderGuid == deliveryOption.OrderGuid).FirstOrDefault(); if (orderAddress != null) { orderAddress.Address = deliveryOption.ShippingAddress.Address; orderAddress.Country = deliveryOption.ShippingAddress.Country; orderAddress.CountryGuid = deliveryOption.ShippingAddress.CountryGuid; orderAddress.FK_CityGuid = deliveryOption.ShippingAddress.CityGuid; orderAddress.Latitude = deliveryOption.ShippingAddress.Latitude; orderAddress.Longitude = deliveryOption.ShippingAddress.Longitude; orderAddress.MobileNumber = deliveryOption.MobileNumber; orderAddress.PlaceId = deliveryOption.ShippingAddress.PlaceId; orderAddress.PostCode = deliveryOption.ShippingAddress.PostCode; } else { orderAddress = new tblOrderAddress(); orderAddress.OrderAddressGuid = Guid.NewGuid(); orderAddress.Address = deliveryOption.ShippingAddress.Address; orderAddress.Country = deliveryOption.ShippingAddress.Country; orderAddress.CountryGuid = deliveryOption.ShippingAddress.CountryGuid; orderAddress.DateCreated = DateTime.Now; orderAddress.FK_CityGuid = deliveryOption.ShippingAddress.CityGuid; orderAddress.FK_OrderGuid = deliveryOption.OrderGuid; orderAddress.FK_UserGuid = deliveryOption.UserGuid; orderAddress.Latitude = deliveryOption.ShippingAddress.Latitude; orderAddress.Longitude = deliveryOption.ShippingAddress.Longitude; orderAddress.MobileNumber = deliveryOption.MobileNumber; orderAddress.PlaceId = deliveryOption.ShippingAddress.PlaceId; orderAddress.PostCode = deliveryOption.ShippingAddress.PostCode; bringlyEntities.tblOrderAddresses.Add(orderAddress); } var shippingAddress = bringlyEntities.tblUserAddresses .Where(z => z.IsDeleted == false && z.AddressType.Equals("Shipping", StringComparison.OrdinalIgnoreCase) && z.FK_UserGuid == deliveryOption.UserGuid).FirstOrDefault(); if (shippingAddress != null) { shippingAddress.Address = deliveryOption.ShippingAddress.Address; shippingAddress.Country = deliveryOption.ShippingAddress.Country; shippingAddress.CountryGuid = deliveryOption.ShippingAddress.CountryGuid; shippingAddress.FK_CityGuid = deliveryOption.ShippingAddress.CityGuid; shippingAddress.FK_UserGuid = deliveryOption.UserGuid; shippingAddress.PostCode = deliveryOption.ShippingAddress.PostCode; } else { shippingAddress = new tblUserAddress(); shippingAddress.UserAddressGuid = Guid.NewGuid(); shippingAddress.AddressType = "Shipping"; shippingAddress.Address = deliveryOption.ShippingAddress.Address; shippingAddress.Country = deliveryOption.ShippingAddress.Country; shippingAddress.CountryGuid = deliveryOption.ShippingAddress.CountryGuid; shippingAddress.DateCreated = DateTime.Now; shippingAddress.FK_CityGuid = deliveryOption.ShippingAddress.CityGuid; shippingAddress.FK_UserGuid = deliveryOption.UserGuid; shippingAddress.Latitude = deliveryOption.ShippingAddress.Latitude; shippingAddress.Longitude = deliveryOption.ShippingAddress.Longitude; shippingAddress.PlaceId = deliveryOption.ShippingAddress.PlaceId; shippingAddress.PostCode = deliveryOption.ShippingAddress.PostCode; shippingAddress.IsDeleted = false; bringlyEntities.tblUserAddresses.Add(shippingAddress); } bringlyEntities.SaveChanges(); return(true); }