public bool AddCurrentLocation(int orderID, string address, decimal lat, decimal log) { try { using (var da = new CourierEntities()) { //check if orderid exit if (Orders.CheckOrder(orderID)) { //ensure no dublicate of an id is found var CheckOrderID = da.CurrentLocations.Where(a => a.OrderID == orderID).SingleOrDefault(); if (CheckOrderID == null) { // add new record var curr = new Courier.Models.DbModel.CurrentLocation { Address = address, Latitude = lat, Logitude = log, OrderID = orderID, }; da.CurrentLocations.Add(curr); //update track entity with order id da.SaveChanges(); //update track entity with order id var tra = da.Tracks.Where(a => a.OrderID == orderID).SingleOrDefault(); tra.CurrentLocationID = curr.CurrentLocationID; da.Entry(tra).State = System.Data.Entity.EntityState.Modified; da.SaveChanges(); return(true); } else { //Update Current Location UpdateCurrentLocation(orderID, address, lat, log); return(true); } } } return(false); } catch (Exception ex) { returnMsg = "This Order has been created you can only update it. "; value = 1; return(false); } }
public bool UpdateLocation(int LocationID, string currentLocation) { try { using (var da = new CourierEntities()) { var query = da.Locations.Find(LocationID); if (query != null) { query.CurrentLocation = currentLocation; da.Entry(query).State = System.Data.Entity.EntityState.Modified; da.SaveChanges(); return(true); } else { returnMsg = "Unable to update record, Record not Found"; return(false); } } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool DeleteOrder(int OrderID) { try { using (var da = new CourierEntities()) { var query = da.Orders.Find(OrderID); if (query != null) { da.Orders.Remove(query); da.SaveChanges(); return(true); } else { returnMsg = "No Record found to delete"; return(false); } } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool EditOrder(int OrderID, string packageName, string des, string weight, string height) { try { using (var da = new CourierEntities()) { var query = da.Orders.Find(OrderID); if (query != null) { query.Packagename = packageName; query.Description = des; query.height = height; query.weight = weight; } da.Entry(query).State = System.Data.Entity.EntityState.Modified; da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
//try // { // } // catch (Exception ex) // { // returnMsg = ex.Message; // return false; // } public bool createReceipt(int orderID, decimal Amount) { try { using (var da = new CourierEntities()) { var chKRec = da.Receipts.Where(a => a.OrderID == orderID).SingleOrDefault(); if (chKRec == null) { // add new record da.Receipts.Add(new Receipt() { Amount = Amount, OrderID = orderID, DateCreated = DateTime.UtcNow }); } else { chKRec.Amount = Amount; da.Entry(chKRec).State = System.Data.Entity.EntityState.Modified; } da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool createOrder(string userID, string packagename, string description, string weight, string height) { try { using (var da = new CourierEntities()) { var order = new Order() { userId = userID, Packagename = packagename, Description = description, weight = weight, height = height, DateSpam = DateTime.UtcNow, }; da.Orders.Add(order); da.SaveChanges(); OrderID = order.OrderID; return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool UpdateSource(int orderID, string address, decimal lat, decimal log) { try { using (var da = new CourierEntities()) { //check if orderid exit if (Orders.CheckOrder(orderID)) { //ensure no dublicate of an id is found var CheckOrderID = da.Sources.Where(a => a.OrderID == orderID).SingleOrDefault(); if (CheckOrderID != null) { //update track entity with order id CheckOrderID.address = address; CheckOrderID.Latitude = lat; CheckOrderID.Logitude = log; da.Entry(CheckOrderID).State = System.Data.Entity.EntityState.Modified; da.SaveChanges(); return(true); } } } return(false); } catch (Exception ex) { returnMsg = "This Order has been created you can only update it. " + ex; value = 1; return(false); } }
public bool AddSource(int orderID, string address, decimal lat, decimal log) { try { using (var da = new CourierEntities()) { //check if orderid exit if (Orders.CheckOrder(orderID)) { //ensure no dublicate of an id is found var CheckOrderID = da.Sources.Where(a => a.OrderID == orderID).SingleOrDefault(); if (CheckOrderID == null) { // add new record da.Sources.Add(new DbModel.Source { address = address, Latitude = lat, Logitude = log, OrderID = orderID, }); da.SaveChanges(); return(true); } } } return(true); } catch (Exception ex) { returnMsg = "This Order has been created you can only update it. " + ex.Message; value = 1; return(false); } }
public bool RespondQuota(int quotaId, string message) { try { using (var da = new CourierEntities()) { var chk = da.Responses.Where(a => a.QuotaID == quotaId).SingleOrDefault(); if (chk == null) { da.Responses.Add(new Response() { QuotaID = quotaId, Message = message }); } else { //update quota chk.Message = message; da.Entry(chk).State = System.Data.Entity.EntityState.Modified; } da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool GenerateTrack(int orderID) { try { using (var da = new CourierEntities()) { var checkOrderId = da.Tracks.Where(a => a.OrderID == orderID).Select(a => a.OrderID).SingleOrDefault(); if (checkOrderId == null) { string trackID = Convert.ToString(Generators.RandomNumber(5)); int destinationID = Convert.ToInt16(da.destinations.Where(a => a.OrderID == orderID).Select(a => a.DestinationID).SingleOrDefault()); int sourceID = Convert.ToInt16(da.Sources.Where(a => a.OrderID == orderID).Select(a => a.SourceID).SingleOrDefault()); int currentID = Convert.ToInt16(da.CurrentLocations.Where(a => a.OrderID == orderID).Select(a => a.CurrentLocationID).SingleOrDefault()); if (currentID != 0) { da.Tracks.Add(new DbModel.Track { TrackID = Generators.Numbergen(6).ToString(), DestinationID = destinationID, SourceID = sourceID, CurrentLocationID = currentID, OrderID = orderID, }); } else { da.Tracks.Add(new DbModel.Track { TrackID = Generators.Numbergen(6).ToString(), DestinationID = destinationID, SourceID = sourceID, OrderID = orderID, }); } da.SaveChanges(); return(true); } return(false); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool BlockUser(int quotaId) { try { using (var da = new CourierEntities()) { var q = da.Quotas.Find(quotaId); da.Quotas.Remove(q); da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool DeleteSupport(int ticketID) { try { using (var da = new CourierEntities()) { var q = da.Quotas.Find(ticketID); da.Quotas.Remove(q); da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool DeleteUser(string userId) { try { using (var da = new CourierEntities()) { var q = da.Users.Find(userId); da.Users.Remove(q); // q. da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool UpdateQuotaReply(int quotaId, string message) { try { using (var da = new CourierEntities()) { var q = da.Responses.Where(a => a.QuotaID == quotaId).SingleOrDefault(); q.Message = message; da.Entry(q).State = System.Data.Entity.EntityState.Modified; da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool ReplyResponse(int responseID, string messsage) { try { using (var da = new CourierEntities()) { da.ResponseReplies.Add(new ResponseReply() { Message = messsage, ResponseID = responseID }); da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool addLocation(int orderId, string destination, string source, string currentLocation) { try { using (var da = new CourierEntities()) { var CheckOrderID = da.Locations.Where(a => a.OrderID == orderId).SingleOrDefault(); if (CheckOrderID == null) { da.Locations.Add( new DbModel.Location() { OrderID = orderId, Destination = destination, Source = source, CurrentLocation = currentLocation, DateSpam = DateTime.UtcNow } ); } else { //return Order Location has already been add returnMsg = "This Order has been created you can only update it. "; value = 1; return(false); } da.SaveChanges(); } return(true); } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
//try // { // } // catch (Exception ex) // { // returnMsg = ex.Message; // return false; // } public bool createQuota(string source, string destination, string packageinfo, string email) { try { using (var da = new CourierEntities()) { da.Quotas.Add(new Quota() { Destination = destination, Source = source, PackageInfo = packageinfo, email = email }); da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool sendSupportMessage(string email, string message) { try { using (var da = new CourierEntities()) { da.supports.Add( new support() { email = email, message = message, dateSpam = DateTime.UtcNow }); da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool AddCrediential(string userId, string email, string password) { try { using (var da = new CourierEntities()) { da.UserCredentials.Add(new UserCredential() { Email = email, Password = password, UserId = userId }); da.SaveChanges(); return(true); } return(false); } catch (Exception ex) { returnMsg = ex.Message; return(false); } }
public bool UpdateReceipt(int ReceiptID, decimal amount) { try { using (var da = new CourierEntities()) { var query = (from p in da.Receipts where p.ReceiptID == ReceiptID select p).SingleOrDefault(); if (query != null) { query.Amount = amount; } da.Entry(query).State = System.Data.Entity.EntityState.Modified; da.SaveChanges(); return(true); } } catch (Exception ex) { returnMsg = ex.Message; return(false); } }