public ActionResult LocationUpdate(int id) { var da = new CourierEntities(); var r = new Courier.Models.ViewModels.LocationV(); var query = da.Tracks.Where(a => a.OrderID == id).SingleOrDefault(); if (query != null) { if (query.CurrentLocation != null) { r.CurrentLatitude = Convert.ToDecimal(query.CurrentLocation.Latitude); r.CurrentLogitude = Convert.ToDecimal(query.CurrentLocation.Logitude); r.CurrentLocation = query.CurrentLocation.Address; } r.DestinationLatitude = Convert.ToDecimal(query.destination.Latitude); r.DestinationLogitude = Convert.ToDecimal(query.destination.Logitude); r.Destination = query.destination.Address; r.SourceLatitude = Convert.ToDecimal(query.Source.Latitude); r.SourceLogitude = Convert.ToDecimal(query.Source.Logitude); r.Source = query.Source.address; } return(View(r)); }
public IEnumerable <DbModel.Track> GetTracks(string email) { try { using (var da = new CourierEntities()) { da.Tracks.Include(a => a.Order); da.Tracks.Include(a => a.Order.User); da.Tracks.Include(a => a.destination); da.Tracks.Include(a => a.Source); da.Tracks.Include(a => a.CurrentLocation); var q = (from p in da.Tracks where p.Order.User.Email == email select p).ToList(); if (q != null) { return(q); } } return(null); } catch (Exception ex) { returnMsg = ex.Message; return(null); } }
//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 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 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 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 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); } }
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 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 ActionResult RespondToSupport(int id) { var db = new CourierEntities(); string email = ViewBag.Email = db.supports.Where(a => a.TicketID == id).Select(a => a.email).SingleOrDefault(); Session["email"] = email; return(View()); }
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 ActionResult Order(string sortOrder, string currentFilter, string searchString, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.OrderID = String.IsNullOrEmpty(sortOrder) ? "orderId" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var da = new CourierEntities(); var orders = from s in da.Tracks select s; if (!String.IsNullOrEmpty(searchString)) { orders = orders.Where(s => s.Order.Packagename.Contains(searchString) ); } switch (sortOrder) { case "orderId": orders = orders.OrderByDescending(s => s.Order.OrderID); break; case "Date": orders = orders.OrderBy(s => s.Order.DateSpam); break; case "date_desc": orders = orders.OrderByDescending(s => s.Order.DateSpam); break; default: // Name ascending orders = orders.OrderByDescending(s => s.Order.DateSpam); break; } int pageSize = 10; int pageNumber = (page ?? 1); return(View(orders.ToPagedList(pageNumber, pageSize))); }
public ActionResult Quotas(string sortOrder, string currentFilter, string searchString, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.Quota = String.IsNullOrEmpty(sortOrder) ? "Quota" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var da = new CourierEntities(); var quota = from s in da.Quotas select s; if (!String.IsNullOrEmpty(searchString)) { quota = quota.Where(s => s.Destination.Contains(searchString) || s.Source.Contains(searchString) || s.email.Contains(searchString) ); } switch (sortOrder) { case "orderId": quota = quota.OrderByDescending(s => s.QuotaID); break; case "Date": quota = quota.OrderBy(s => s.DateSpam); break; case "date_desc": quota = quota.OrderByDescending(s => s.DateSpam); break; default: // Name ascending quota = quota.OrderByDescending(s => s.DateSpam); break; } int pageSize = 10; int pageNumber = (page ?? 1); return(View(quota.ToPagedList(pageNumber, pageSize))); }
public ActionResult EditOrder(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var da = new CourierEntities(); var order = da.Orders.Find(id); if (order == null) { return(HttpNotFound()); } return(View(order)); }
public ActionResult UpdateLocation(int id) { var checkID = Orders.CheckOrder(id); if (checkID) { var da = new CourierEntities(); var q = da.Orders.Where(a => a.OrderID == id).SingleOrDefault(); Session["PackageName"] = q.Packagename; ViewBag.TrackingNo = Convert.ToString(Session["TrackingNo"] = da.Tracks.Where(a => a.OrderID == id).Select(a => a.TrackID).SingleOrDefault()); @ViewBag.PackageName = Convert.ToString(Session["PackageName"]); } return(View()); }
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 List <UserCredential> UserCrediential() { try { using (var da = new CourierEntities()) { return(da.UserCredentials.ToList()); } return(null); } catch (Exception ex) { returnMsg = ex.Message; return(null); } }
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 ActionResult GenerateReceipt(int id) { ReceiptV m = new ReceiptV(); if (new Orders().FindOrder(id)) { var da = new CourierEntities(); var packageName = da.Orders.Where(a => a.OrderID == id).Select(a => a.Packagename).SingleOrDefault(); var userEmail = da.Orders.Where(a => a.OrderID == id).Select(a => a.User.Email).SingleOrDefault(); var Orderno = da.Orders.Where(a => a.OrderID == id).Select(a => a.OrderID).SingleOrDefault(); ViewBag.OrderNo = (Session["OrderNo"] = Orderno).ToString(); ViewBag.PackageName = (Session["packageName"] = packageName).ToString(); ViewBag.UserEmail = (Session["userEmail"] = userEmail).ToString(); m.orderID = Orderno; } return(View(m)); }
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 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 ActionResult LocationUpdate(int id, LocationV m) { var da = new CourierEntities(); if (new Orders().FindOrder(id)) { var update = new Courier.Models.Location(); var curr = update.AddCurrentLocation(id, m.CurrentLocation, m.CurrentLatitude, m.CurrentLogitude); var des = update.UpdateDestination(id, m.Destination, m.DestinationLatitude, m.DestinationLogitude); var sou = update.UpdateSource(id, m.Source, m.SourceLatitude, m.SourceLogitude); if (curr && des && sou) { return(RedirectToAction("Order")); } } return(View()); }
public ActionResult RespondToSupport(int id, supportReply m) { var db = new CourierEntities(); string email = ViewBag.Email = db.supports.Where(a => a.TicketID == id).Select(a => a.email).SingleOrDefault(); Session["email"] = email; m.TicketID = id; if (new SupportW().RespondSupport(id, m.Message)) { TempData["show"] = 1; return(View()); } return(View(m)); }
public IEnumerable <Order> GetOrders() { try { using (var da = new CourierEntities()) { var q = (from p in da.Orders select p).ToList(); if (q != null) { return(q); } } return(null); } catch (Exception ex) { returnMsg = ex.Message; return(null); } }
public ActionResult RespondToQuota(int id, QuotaReplyV m) { var db = new CourierEntities(); string email = ViewBag.Email = db.Quotas.Where(a => a.QuotaID == id).Select(a => a.email).SingleOrDefault(); Session["email"] = email; m.QuotaID = id; if (new Quotas().RespondQuota(id, m.QuotaMessage)) { TempData["show"] = 1; return(View()); } return(View(m)); }
public IEnumerable <Quota> GetQuota(string email) { try { using (var da = new CourierEntities()) { var q = (from p in da.Quotas where p.email == email select p).ToList(); if (q != null) { return(q); } } return(null); } catch (Exception ex) { returnMsg = ex.Message; return(null); } }
public IEnumerable <Receipt> GetReceipts(string email) { try { using (var da = new CourierEntities()) { var q = (from p in da.Receipts where p.Order.User.Email == email select p).ToList(); if (q != null) { return(q); } } return(null); } catch (Exception ex) { returnMsg = ex.Message; return(null); } }
public bool FindOrder(int id) { try { using (var da = new CourierEntities()) { var q = (from p in da.Orders where p.OrderID == id select p); if (q != null) { return(true); } } } catch (Exception ex) { returnMsg = ex.Message; return(false); } 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); } }