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 GetById(int id) { using (CTSContext context = new CTSContext()) { var model = context.CourierCompanys .FirstOrDefault(p => p.Id == id); return Json(new AjaxResult("查询成功", AjaxResultType.Success, model), JsonRequestBehavior.AllowGet); } }
public Send GetById(int id) { using (CTSContext context = new CTSContext()) { var model = context.Sends .Include(p => p.BelongCompany) .FirstOrDefault(p => p.Id == id); return model; } }
public ActionResult List(PagedParam<dynamic> queryCond) { using (CTSContext context = new CTSContext()) { var result = context.CourierCompanys .Where(p => !p.IsDeleted) .OrderByDescending(p => p.CreatedTime).ToPagedList(queryCond.PageNo, queryCond.PageSize); return Json(new AjaxResult("查询成功", AjaxResultType.Success, new { rows = result.ToList(), total = result.TotalItemCount })); } }
public ActionResult Add(CourierCompany model) { using (CTSContext context = new CTSContext()) { context.CourierCompanys.Add(model); context.SaveChanges(); return Json(new AjaxResult("添加成功", AjaxResultType.Success)); } }
public IPagedList<Send> List(PagedParam<SendQueryDto> queryCond) { using (CTSContext context = new CTSContext()) { var express = context.Sends .Include(p => p.BelongCompany) .Where(p => !p.IsDeleted); if (queryCond.QueryDto != null) { if (!string.IsNullOrEmpty(queryCond.QueryDto.CourierNumber)) { express = express.Where(p => p.CourierNumber.Equals(queryCond.QueryDto.CourierNumber)); } if (!string.IsNullOrEmpty(queryCond.QueryDto.CustomerPhone)) { express = express.Where(p => p.CustomerPhone.Equals(queryCond.QueryDto.CustomerPhone) || p.CustomerPhone.Contains(queryCond.QueryDto.CustomerPhone)); } if (queryCond.QueryDto.BelongCompanyId.HasValue) { if (queryCond.QueryDto.BelongCompanyId.Value != 0) { express = express.Where(p => p.BelongCompany.Id == queryCond.QueryDto.BelongCompanyId.Value); } } if (queryCond.QueryDto.State.HasValue) { if (queryCond.QueryDto.State != 0) { if (queryCond.QueryDto.State == 1) { express = express.Where(p => !p.IsSendOut); } else { express = express.Where(p => p.IsSendOut); } } } if (queryCond.QueryDto.CreatedTimeStart.HasValue) { express = express.Where(p => p.CreatedTime >= queryCond.QueryDto.CreatedTimeStart.Value); } if (queryCond.QueryDto.CreatedTimeEnd.HasValue) { var dt = queryCond.QueryDto.CreatedTimeEnd.Value.AddDays(1); express = express.Where(p => p.CreatedTime < dt); } } express = express.OrderByDescending(p => p.CreatedTime); var result = express.ToPagedList(queryCond.PageNo, queryCond.PageSize); return result; } }
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 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)); } }
// GET api/couriercompanyapi public IEnumerable<ComboData> Get() { using (CTSContext context = new CTSContext()) { var result = context.CourierCompanys .Where(p => !p.IsDeleted) .Select(s => new ComboData { id = s.Id, text = s.CourierName }).ToList(); return result; } }
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 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 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 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 GetById(int id) { using (CTSContext context = new CTSContext()) { var model = context.Receipts .Include(p => p.BelongCompany) .Include(p=>p.TakeInfo) .FirstOrDefault(p => p.Id == id); return Json(new AjaxResult("查询成功", AjaxResultType.Success, model)); } }
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(); } }
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 ActionResult Print(int[] ids) { using (CTSContext context = new CTSContext()) { var list = context.Receipts .Include(p => p.BelongCompany) .Include(p => p.TakeInfo) .Where(p => ids.Contains(p.Id)).ToList(); if (list.GroupBy(g => g.CustomerPhone).Count() > 1) { throw new BusinessException("打印快递单中存在不是同一手机号的快递"); } new Printer().Print(list); } return Json(new AjaxResult("打印成功", AjaxResultType.Success)); }
public ActionResult List(PagedParam<ReceiptQueryDto> queryCond) { using (CTSContext context = new CTSContext()) { var express = context.Receipts .Include(p => p.BelongCompany) .Include(p => p.TakeInfo) .Where(p => !p.IsDeleted); if (queryCond.QueryDto != null) { if (!string.IsNullOrEmpty(queryCond.QueryDto.CourierNumber)) { express = express.Where(p => p.CourierNumber.Equals(queryCond.QueryDto.CourierNumber)); } if (!string.IsNullOrEmpty(queryCond.QueryDto.CustomerName)) { express = express.Where(p => p.CustomerName.Contains(queryCond.QueryDto.CustomerName)); } if (!string.IsNullOrEmpty(queryCond.QueryDto.CustomerPhone)) { express = express.Where(p => p.CustomerPhone.Equals(queryCond.QueryDto.CustomerPhone)||p.CustomerPhone.Contains(queryCond.QueryDto.CustomerPhone)); } if (queryCond.QueryDto.BelongCompanyId.HasValue) { if (queryCond.QueryDto.BelongCompanyId.Value != 0) { express = express.Where(p => p.BelongCompany.Id == queryCond.QueryDto.BelongCompanyId.Value); } } if (queryCond.QueryDto.State.HasValue) { if (queryCond.QueryDto.State != 0) { if (queryCond.QueryDto.State == 1) { express = express.Where(p => p.TakeInfo == null); } else { express = express.Where(p => p.TakeInfo != null); } } } if (queryCond.QueryDto.CreatedTimeStart.HasValue) { express = express.Where(p => p.CreatedTime >= queryCond.QueryDto.CreatedTimeStart.Value); } if (queryCond.QueryDto.CreatedTimeEnd.HasValue) { var dt=queryCond.QueryDto.CreatedTimeEnd.Value.AddDays(1); express = express.Where(p => p.CreatedTime < dt); } } express=express.OrderByDescending(p => p.CreatedTime); var result = express.ToPagedList(queryCond.PageNo, queryCond.PageSize); return Json(new AjaxResult("查询成功", AjaxResultType.Success, new { rows = result.ToList(), total = result.TotalItemCount })); } }
public ActionResult GetCourierCompanyList(int? tag) { using (CTSContext context = new CTSContext()) { var result = context.CourierCompanys .Where(p => !p.IsDeleted) .Select(s => new ComboData { id = s.Id, text = s.CourierName }).ToList(); if (tag != null) { result.Add(new ComboData { id = 0, text = "请选择" }); } return Json(result.OrderBy(o=>o.id),JsonRequestBehavior.AllowGet); } }