Beispiel #1
0
        public ActionResult Details(int?id)
        {
            shNewService _tintuc = new shNewService();
            shNew        tintuc  = _tintuc.FindList().Where(x => x.NewId == id).FirstOrDefault();

            if (tintuc == null)
            {
                tintuc = new shNew();
            }



            return(View(tintuc));
        }
Beispiel #2
0
        public ActionResult Create(string id)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                shNewService _new   = new shNewService();
                shNew        tintuc = _new.FindByKey(id);

                if (tintuc != null)
                {
                    return(View(tintuc));
                }
                else
                {
                    return(View(new shNew()));
                }
            }

            return(View(new shNew()));
        }
Beispiel #3
0
        public ActionResult Create(string NewGuiId, int?NewId, string TitleNew, int?SortOrder, string Descriptions, string Summary, string Contents, bool?Status, string ImageFile)
        {
            shNewService _new = new shNewService();

            using (var context = new ShopOnlineDb())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(NewGuiId))
                        {
                            NewId = 0;
                        }

                        // check if contents (  ckeditor) null then rollback và yêu cầu người dùng nhập lại
                        if (string.IsNullOrEmpty(Contents))
                        {
                            shNew shnew = _new.FindByKey(NewGuiId);
                            if (shnew == null)
                            {
                                shnew = new shNew();
                            }

                            //shnew.NewId = NewId.Value;
                            //shnew.Title = Title1;
                            ViewBag.TitleNew   = TitleNew;
                            shnew.SortOrder    = SortOrder;
                            shnew.Descriptions = Descriptions;
                            shnew.Summary      = Summary;
                            shnew.Contents     = Contents;
                            shnew.Status       = Status;

                            shnew.ImageFile = ImageFile;

                            ModelState.AddModelError("", "Nội dung không được trống. Xin Vui lòng kiểm tra lại. ");
                            return(View(shnew));
                        }

                        shNew tintuc = _new.ThemMoi_HieuChinhshNew(
                            NewGuiId,
                            null,
                            TitleNew,
                            Descriptions,
                            ImageFile,
                            Summary,
                            Contents,
                            SortOrder,
                            Status,
                            DateTime.Now);
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }


            return(RedirectToAction("Index"));
        }