public void Delete(int id) { using (CTSContext context = new CTSContext()) { var send = context.Sends.FirstOrDefault(p => p.Id == id); send.IsDeleted = true; context.SaveChanges(); } }
public ActionResult Add(CourierCompany model) { using (CTSContext context = new CTSContext()) { context.CourierCompanys.Add(model); context.SaveChanges(); return Json(new AjaxResult("添加成功", AjaxResultType.Success)); } }
public ActionResult Delete(int id) { using (CTSContext context = new CTSContext()) { context.Receipts.FirstOrDefault(p => p.Id == id).IsDeleted = true; context.SaveChanges(); return Json(new AjaxResult("删除成功", AjaxResultType.Success)); } }
public void Add(Customer model) { using (CTSContext context = new CTSContext()) { if (!context.Customers.Any(p => p.CustomerName.Equals(model.CustomerName) && p.CustomerPhone.Equals(model.CustomerPhone))) { context.Customers.Add(model); context.SaveChanges(); } } }
public ActionResult Edit(CourierCompany model) { using (CTSContext context = new CTSContext()) { var courierCompany = context.CourierCompanys.FirstOrDefault(p => p.Id == model.Id); courierCompany.ContactMobilePhone = model.ContactMobilePhone; courierCompany.ContactName = model.ContactName; courierCompany.ContactPhone = model.ContactPhone; courierCompany.CourierCode = model.CourierCode; courierCompany.CourierName = model.CourierName; courierCompany.IsSendSMS = model.IsSendSMS; courierCompany.Remark = model.Remark; context.SaveChanges(); return Json(new AjaxResult("编辑成功", AjaxResultType.Success)); } }
public void Add(Send model) { using (CTSContext context = new CTSContext()) { if (model.BelongCompany.Id > 0) { model.BelongCompany = context.CourierCompanys.FirstOrDefault(p => p.Id == model.BelongCompany.Id); } else { model.BelongCompany = null; } context.Sends.Add(model); context.SaveChanges(); } }
public ActionResult Add(Receipt model) { using (CTSContext context = new CTSContext()) { model.BelongCompany = context.CourierCompanys.FirstOrDefault(p => p.Id == model.BelongCompany.Id); if (!context.Customers.Any(p => p.CustomerPhone.Equals(model.CustomerPhone))) { context.Customers.Add(new Customer() { CustomerName = model.CustomerName, CustomerPhone = model.CustomerPhone }); } context.Receipts.Add(model); context.SaveChanges(); return Json(new AjaxResult("添加成功", AjaxResultType.Success)); } }
public void Edit(Send model) { using (CTSContext context = new CTSContext()) { var send = context.Sends.FirstOrDefault(p => p.Id == model.Id); if (model.BelongCompany.Id > 0) { send.BelongCompany = context.CourierCompanys.FirstOrDefault(p => p.Id == model.BelongCompany.Id); } send.CourierNumber = model.CourierNumber; send.CustomerAddress = model.CustomerAddress; send.CustomerName = model.CustomerName; send.CustomerPhone = model.CustomerPhone; send.RecipientAddress = model.RecipientAddress; send.RecipientName = model.RecipientName; send.RecipientPhone = model.RecipientPhone; send.Price = model.Price; send.Weight = model.Weight; send.Remark = model.Remark; context.SaveChanges(); } }
public ActionResult Edit(Receipt model) { using (CTSContext context = new CTSContext()) { var receipts = context.Receipts.FirstOrDefault(p => p.Id == model.Id); receipts.BelongCompany = context.CourierCompanys.FirstOrDefault(p => p.Id == model.BelongCompany.Id); receipts.CourierNumber = model.CourierNumber; receipts.CustomerAddress = model.CustomerAddress; receipts.CustomerName = model.CustomerName; receipts.CustomerPhone = model.CustomerPhone; receipts.Remark = model.Remark; context.SaveChanges(); return Json(new AjaxResult("编辑成功", AjaxResultType.Success)); } }
public ActionResult Take(FormCollection from,int[] ids) { using (CTSContext context = new CTSContext()) { var receipts = context.Receipts .Include(p => p.BelongCompany) .Include(p => p.TakeInfo) .Where(p => ids.Contains(p.Id)).ToList(); if (receipts.GroupBy(g => g.CustomerPhone).Count() > 1) { throw new BusinessException("取件时存在不是同一手机号的快递"); } foreach (var item in receipts) { item.TakeInfo = new TakeInfo(); Customer customer = new Customer(); customer.CustomerPhone = item.CustomerPhone; customer.CustomerName = item.CustomerName; customer.CustomerAddress = item.CustomerAddress; context.Customers.Add(customer); } context.SaveChanges(); new Printer().Print(receipts); return Json(new AjaxResult("取件并打印成功", AjaxResultType.Success)); } }
public void SendOut(int sendId, string courierNumber, int? courierCompanyId) { using (CTSContext context = new CTSContext()) { var model = context.Sends .Include(p => p.BelongCompany) .FirstOrDefault(p => p.Id == sendId); Customer customer = new Customer(); customer.CustomerPhone = model.CustomerPhone; customer.CustomerName = model.CustomerName; customer.CustomerAddress = model.CustomerAddress; context.Customers.Add(customer); if (!string.IsNullOrEmpty(courierNumber)) { model.CourierNumber = courierNumber; } if (courierCompanyId.HasValue) { model.BelongCompany = context.CourierCompanys.FirstOrDefault(p => p.Id == courierCompanyId); } //if (string.IsNullOrEmpty(model.CourierNumber)) //{ // throw new BusinessException("发件时,快递单号不能为空"); //} if (model.BelongCompany == null) { throw new BusinessException("发件时,快递公司不能为空"); } model.IsSendOut = true; context.SaveChanges(); } }