예제 #1
0
        public ActionResult SaveExp(ExpList model)
        {
            //var m = model;
            try
            {
                using (yxbDbContext con = new yxbDbContext())
                {
                    //时间戳
                    model.ExpTime = DateTime.Now;
                    var list = con.ExpList.AsNoTracking().Where(o => o.ExpId == model.ExpId && o.IsDeleted == 0).ToList();
                    if (list.Count() > 0)
                    {
                        var exist = con.ExpList.AsNoTracking().Where(o => o.ExpNo == model.ExpNo && o.ExpId != model.ExpId && o.IsDeleted == 0);
                        if (exist.Count() > 0)
                        {
                            return Json(CommenData.ResultMsg(2, "该单号已录入,请查证后输入。"), JsonRequestBehavior.AllowGet);
                        }
                        else
                        {
                            con.Entry(model).State = System.Data.Entity.EntityState.Modified;
                            // int expno = list.First();

                            List<ExpContext> expdetail = con.ExpContext.Where(o => o.expid == model.ExpId).ToList();
                            foreach (ExpContext ec in expdetail)
                            {
                                ec.expno = model.ExpNo;
                            }


                            con.SaveChanges();

                            //签收短信通知
                            ExpStateEnum s = (ExpStateEnum)model.ExpState;
                            switch (s)
                            {
                                case ExpStateEnum.OnSign:
                                    //短信模板参数
                                    List<string> smsdata = new List<string>();
                                    smsdata.Add(model.From);
                                    smsdata.Add(model.To);
                                    smsdata.Add(model.ExpNo);
                                    smsdata.Add(ExpSMSTemp.ContactTel);

                                    SendExpSMS ss = new SendExpSMS();
                                    if (!string.IsNullOrWhiteSpace(model.From))
                                    {
                                        ExpSMSResponse ret = ss.SendSMS(model.ToMobile, ExpSMSTemp.SignTempId, smsdata.ToArray());
                                    }
                                    break;
                            }
                            return Json(CommenData.ResultMsg(1, "信息修改成功"), JsonRequestBehavior.AllowGet);

                        }
                    }
                    else
                    {
                        var exist = con.ExpList.AsNoTracking().Where(o => o.ExpNo == model.ExpNo && o.IsDeleted == 0);
                        if (exist.Count() > 0)
                        {
                            return Json(CommenData.ResultMsg(2, "该单号已录入,请查证后输入。"), JsonRequestBehavior.AllowGet);
                        }
                        else
                        {
                            con.ExpList.Add(model);

                            con.SaveChanges();
                            //添加详情
                            ExpContext expDetail = new ExpContext();
                            expDetail.expno = model.ExpNo;
                            expDetail.context = "揽件扫描";
                            expDetail.time = DateTime.Now;
                            expDetail.expid = model.ExpId;


                            con.ExpContext.Add(expDetail);
                            con.SaveChanges();
                            //短信模板参数
                            List<string> smsdata = new List<string>();
                            smsdata.Add(model.StartStation);
                            smsdata.Add(model.ExpNo);
                            smsdata.Add(ExpSMSTemp.ContactTel);

                            SendExpSMS ss = new SendExpSMS();
                            ExpSMSResponse ret = ss.SendSMS(model.ToMobile, ExpSMSTemp.SendTempId, smsdata.ToArray());

                            return Json(CommenData.ResultMsg(1, ""), JsonRequestBehavior.AllowGet);

                        }

                    }
                }
            }
            catch (Exception ex)
            {
                return Json(CommenData.ResultMsg(-1, ex.Message), JsonRequestBehavior.AllowGet);
            }

        }
예제 #2
0
        public ActionResult ExpEdit(int id)
        {
            if (id > 0)
            {
                using (yxbDbContext con = new yxbDbContext())
                {

                    ExpList exp = con.ExpList.SingleOrDefault(o => o.ExpId == id);
                    return View(exp);
                }
            }
            else
            {
                ExpList exp = new ExpList();
                exp.ExpDate = DateTime.Now;
                exp.ExpTime = DateTime.Now;
                return View(exp);
            }
        }