コード例 #1
0
 //
 // GET: /NguoiDatHang/Create
 public ActionResult Create()
 {
     if (Session["ID"] != null)
     {
         ViewData["TinhThanh"] = CMRes.FindAllTinhThanh();
         Account acc = accountRes.Get(int.Parse(Session["ID"].ToString()));
         var ndh = new NguoiDatHang();
         ndh.HoVaTen = acc.hoTen;
         ndh.DiaChi = acc.DiaChi;
         ndh.Email = acc.email;
         ndh.TinhThanhID = acc.TinhThanhID;
         return PartialView(ndh);
     }
     else {
         Session.Add("UrlRedirect", Url.AbsoluteAction("Create", "NguoiDatHang"));
         return RedirectToAction("LogOn", "Account");
     }
 }
コード例 #2
0
        public ActionResult Create(FormCollection collection)
        {
            if (Session["ID"] != null)
            {
                var ndh = new NguoiDatHang();
                try
                {
                    // TODO: Add insert logic here

                    if (TryUpdateModel(ndh))
                    {
                        ndh.AccountID = int.Parse(Session["ID"].ToString());
                        ndh.NgayDatHang = DateTime.Now;
                        ndh.IsDeleted = false;
                        NDTRes.Add(ndh);
                        NDTRes.Save();
                        var MaDatHang = InsertToDonDatHang(int.Parse(Session["ID"].ToString()), ndh.NguoiDatHangID);
                        return Json(new { message = "FucssecFull", modelReturn = MaDatHang }, "text/html");

                    }
                    else {
                        ViewData["TinhThanh"] = CMRes.FindAllTinhThanh();
                        return Json(new { message = "Validate", modelReturn = this.RenderPartialViewToString("Create", ndh) }, "text/html");

                    }
                }
                catch(Exception e)
                {
                    logger.Debug("Error at function /NguoiDatHang/Create :" + e);
                    ViewData["TinhThanh"] = CMRes.FindAllTinhThanh();
                    return Json(new { message = "Validate", modelReturn = this.RenderPartialViewToString("Create", ndh) }, "text/html");
                }
            }
            else
            {
                Session.Add("UrlRedirect", Url.AbsoluteAction("Create", "NguoiDatHang"));
                return RedirectToAction("LogOn", "Account");
            }
        }