Exemple #1
0
        public async Task <IActionResult> New([Bind(Prefix = "Item1")] EF.Page model, [Bind(Prefix = "Item2")] bool isactive, IFormFile file)
        {
            ViewData["Title"] = "Blog/New";

            try
            {
                model.CreatedBy = User.Identity.Name;

                var bpage = new BLL.Page(unitOfWork);

                // Add Page
                if (!isactive)
                {
                    model.DateInactive = DateTime.Now;
                }

                var id = await bpage.Add(model);

                // Add Photo
                IFormFile uploadedImage = file;
                if (uploadedImage != null && uploadedImage.ContentType.ToLower().StartsWith("image/"))
                {
                    var pid = await new BLL.Photo(unitOfWork).Add(_environment, file);

                    var pp = new EF.PagePhoto();
                    pp.PageId  = id;
                    pp.PhotoId = pid;
                    await new BLL.PagePhoto(unitOfWork).Add(pp);
                }

                return(Redirect("~/Admin/Page"));
            }
            catch (DbUpdateException ex)
            {
                ModelState.AddModelError(string.Empty, "Entry is causing conflict or already exist.");
                return(View(new Tuple <EF.Page, bool>(model, isactive)));
            }
        }