Example #1
0
        public ActionResult Create(INTRODUCTION i, HttpPostedFileBase picture)
        {
            if (ModelState.IsValid)
            {
                var introduction = new INTRODUCTION();
                if (picture != null)
                {
                    if (ModelState.IsValid)
                    {
                        using (var scope = new TransactionScope())
                        {
                            introduction.CONTENT = i.CONTENT;
                            model.INTRODUCTIONs.Add(introduction);
                            model.SaveChanges();

                            var path = Server.MapPath(PICTURE_PATH);
                            picture.SaveAs(path + introduction.ID);
                            scope.Complete();
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Picture not found!");
                }
            }
            return(View());
        }
Example #2
0
        public ActionResult Edit(int id, INTRODUCTION i, HttpPostedFileBase picture)
        {
            if (ModelState.IsValid)
            {
                var product = model.INTRODUCTIONs.FirstOrDefault(x => x.ID == id);
                using (var scope = new TransactionScope())
                {
                    product.CONTENT = i.CONTENT;
                    model.SaveChanges();

                    if (picture != null)
                    {
                        var path = Server.MapPath(PICTURE_PATH);
                        picture.SaveAs(path + product.ID);
                    }
                    scope.Complete();
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }