public int WaypointInsert(WaypointRequest model, int addressId) { int id = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.Jobs_WaypointInsert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@JobId", model.JobId); paramCollection.AddWithValue("@AddressId", addressId); paramCollection.AddWithValue("@SuiteNo", model.SuiteNo); paramCollection.AddWithValue("@ContactName", model.ContactName); paramCollection.AddWithValue("@Phone", model.Phone); paramCollection.AddWithValue("@SpecialInstructions", model.SpecialInstructions); paramCollection.AddWithValue("@ServiceNote", model.ServiceNote); paramCollection.AddWithValue("@ExternalCustomerId", model.ExternalCustomerId); SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); }, returnParameters : delegate(SqlParameterCollection param) { int.TryParse(param["@Id"].Value.ToString(), out id); }); return(id); }
public void WaypointUpdate(WaypointRequest model, int addressId) { DataProvider.ExecuteNonQuery(GetConnection, "dbo.Jobs_WaypointsUpdate" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", model.Id); paramCollection.AddWithValue("@JobId", model.JobId); paramCollection.AddWithValue("@AddressId", addressId); paramCollection.AddWithValue("@SuiteNo", model.SuiteNo); paramCollection.AddWithValue("@ContactName", model.ContactName); paramCollection.AddWithValue("@Phone", model.Phone); paramCollection.AddWithValue("@SpecialInstructions", model.SpecialInstructions); paramCollection.AddWithValue("@ServiceNote", model.ServiceNote); }); }
public int SaveWaypoint(WaypointRequest model) { // we call this so we can attach an AddressId to each Waypoint in WaypointInsert() or WaypointUpdate() int addressId = _AddressService.SaveWaypointAddress(model); if (model.Id == 0) // insert Waypoint { int waypointId = _JobsWaypointService.WaypointInsert(model, addressId); List <int> PickupList = new List <int>(); // every Waypoint has a list of items foreach (var items in model.JobWaypointItemsPickup) //loops through all items in the model { int itemId = SaveItem(items, model.JobId, waypointId); // see comment directly above SaveItem() that explains why we needs this parameters passed in PickupList.Add(itemId); } List <int> DropoffList = new List <int>(); // every Waypoint has a list of items foreach (var items in model.JobWaypointItemsDropOff) //loops through all items in the model { int itemId = SaveItem(items, model.JobId, waypointId); // see comment directly above SaveItem() that explains why we needs this parameters passed in DropoffList.Add(itemId); } return(waypointId); } else // update Waypoint { _JobsWaypointService.WaypointUpdate(model, addressId); int waypointId = model.Id; // we need this to be returned for the list of Waypoints List <int> PickupList = new List <int>(); // every Waypoint, even an updated one, needs a new list because we loop through each waypoint's items after inserting or updating a waypoint foreach (var items in model.JobWaypointItemsPickup) { int itemId = SaveItem(items, model.JobId, waypointId); PickupList.Add(itemId); } List <int> DropoffList = new List <int>(); // every Waypoint, even an updated one, needs a new list because we loop through each waypoint's items after inserting or updating a waypoint foreach (var items in model.JobWaypointItemsDropOff) { int itemId = SaveItem(items, model.JobId, waypointId); DropoffList.Add(itemId); } return(waypointId); } }
public int SaveWaypointAddress(WaypointRequest model) { var addressId = 0; AddressAddRequest newAddress = new AddressAddRequest(); Address CurrentAddress = GetByExternalAddressId(model.Address.ExternalPlaceId); if (CurrentAddress == null) { model.Address.Name = model.ContactName; addressId = Insert(model.Address); } else { AddressUpdateRequest Address = new AddressUpdateRequest(); Address.AddressId = CurrentAddress.AddressId; Address.Name = model.ContactName; Address.ExternalPlaceId = model.Address.ExternalPlaceId; Address.Line1 = model.Address.Line1; Address.City = model.Address.City; Address.State = model.Address.State; Address.ZipCode = model.Address.ZipCode; if (model.Address.Latitude != null && model.Address.Latitude > 0) { Address.Latitude = model.Address.Latitude; } if (model.Address.Longitude != null && model.Address.Longitude > 0) { Address.Longitude = model.Address.Longitude; } Update(Address); addressId = CurrentAddress.AddressId; } return(addressId); }