示例#1
0
        private ActionResult ViewDetail(TblPileSeries ob, string msg, AlertMsgType?msgType)
        {
            try
            {
                if (ob == null)
                {
                    throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง");
                }

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    WidgetAlertModel alert = new WidgetAlertModel()
                    {
                        Message = msg
                    };
                    if (msgType.HasValue)
                    {
                        alert.Type = msgType.Value;
                    }
                    ViewBag.Alert = alert;
                }
                return(View(ob));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", MVCController, new
                {
                    area = MVCArea,
                    msg = ex.GetMessage(),
                    msgType = AlertMsgType.Danger
                }));
            }
        }
示例#2
0
        public ActionResult SetDetail()
        {
            int           id = Request.Form["SeriesId"].ParseInt();
            TblPileSeries ob = db.TblPileSeries.Find(id) ?? new TblPileSeries();

            ob.SeriesName  = Request.Form["SeriesName"];
            ob.SeriesOrder = Request.Form["SeriesOrder"].ParseInt();
            try
            {
                if (Request.Files.Count > 0 && Request.Files["SeriesImage"] != null && Request.Files["SeriesImage"].ContentLength > 0)
                {
                    string             oldPath      = ob.SeriesImage;
                    HttpPostedFileBase uploadedFile = Request.Files["SeriesImage"];
                    string             FilePath     = string.Format("files/products/{0}{1}", CurrentDate.ParseString(DateFormat._yyyyMMddHHmmssfff), Path.GetExtension(uploadedFile.FileName));
                    if (!Directory.Exists(Server.MapPath("~/files")))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/files"));
                    }
                    if (!Directory.Exists(Server.MapPath("~/files/products")))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/files/products"));
                    }
                    uploadedFile.SaveAs(Server.MapPath("~/" + FilePath));
                    ob.SeriesImage = FilePath;
                    if (!string.IsNullOrWhiteSpace(oldPath) && IOFile.Exists(Server.MapPath("~/" + oldPath)))
                    {
                        IOFile.Delete(Server.MapPath("~/" + oldPath));
                    }
                }
                else if (ob.SeriesId <= 0)
                {
                    throw new Exception("กรุณาระบุรูปซีรี่ย์ของสินค้า");
                }
                //Validate model b4 save

                if (ob.SeriesId <= 0)
                {
                    db.TblPileSeries.Add(ob);
                }
                else
                {
                    db.Entry(ob).State = System.Data.Entity.EntityState.Modified;
                }
                db.SaveChanges();

                return(RedirectToAction("Index", new
                {
                    area = "",
                    controller = MVCController,
                    msg = "บันทึกข้อมูลเรียบร้อยแล้ว",
                    msgType = AlertMsgType.Success
                }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage(true);
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
示例#3
0
        public ActionResult Delete()
        {
            try
            {
                int           id = Request.Form["SeriesId"].ParseInt();
                TblPileSeries ob = uow.Modules.PileSeries.Get(id);
                if (ob == null)
                {
                    return(RedirectToAction("Index", MVCController, new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning }));
                }

                uow.Modules.PileSeries.Delete(ob);
                uow.SaveChanges();
                return(RedirectToAction("Index", MVCController, new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            { return(RedirectToAction("Index", MVCController, new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); }
        }
示例#4
0
        public ActionResult Detail(int?id, string msg, AlertMsgType?msgType)
        {
            TblPileSeries ob = uow.Modules.PileSeries.Get(id ?? 0);

            return(ViewDetail(ob, msg, msgType));
        }
示例#5
0
        public ActionResult Detail(int?id, string msg, AlertMsgType?msgType)
        {
            TblPileSeries ob = db.TblPileSeries.Find(id ?? 0) ?? new TblPileSeries();

            return(ViewDetail(ob, msg, msgType));
        }