コード例 #1
0
        public async Task <IActionResult> Index([Bind(Prefix = "Item1")] EF.SectionItem args, int id)
        {
            var section = await new BLL.Section(unitOfWork).Get(new EF.Section {
                SectionId = id
            });

            ViewData["Title"] = "Section/" + section.Name;

            var items = await new BLL.SectionItem(unitOfWork).Find(args);

            var tuple = new Tuple <EF.SectionItem, List <EF.SectionItem> >(args, items.ToList());

            return(View(tuple));
        }
コード例 #2
0
        public async Task <IActionResult> New([Bind(Prefix = "Item1")] EF.SectionItem args, [Bind(Prefix = "Item2")] List <EF.SectionItemProperty> props, IFormFile file, int id)
        {
            // Add SectionItem
            args.CreatedBy    = User.Identity.Name;
            args.DateCreated  = DateTime.Now;
            args.ModifiedBy   = args.CreatedBy;
            args.DateModified = args.DateCreated;
            args.SectionId    = id;
            var siId = await new BLL.SectionItem(unitOfWork).Add(args);

            IFormFile uploadedImage = file;

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

                var siph = new EF.SectionItemPhoto();
                siph.PhotoId       = pid;
                siph.SectionItemId = siId;
                await new BLL.SectionItemPhoto(unitOfWork).Add(siph);
            }

            foreach (var rec in props)
            {
                if (rec.Value != null)
                {
                    // Add SectionItemProperty
                    var sipr = new EF.SectionItemProperty();
                    sipr.SectionItemId     = siId;
                    sipr.SectionPropertyId = rec.SectionPropertyId;
                    sipr.Value             = rec.Value;
                    await new BLL.SectionItemProperty(unitOfWork).Add(sipr);
                }
            }

            return(Redirect("~/Section/" + id + "/Items"));
        }
コード例 #3
0
        public async Task <IActionResult> Edit([Bind(Prefix = "Item1")] EF.SectionItem args, [Bind(Prefix = "Item2")] List <EF.SectionItemProperty> props, IFormFile file, int id, int id1)
        {
            var si = new EF.SectionItem
            {
                SectionItemId = id1,
                SectionId     = id,
                Title         = args.Title,
                Body          = args.Body,
                Order         = args.Order,
                ModifiedBy    = User.Identity.Name,
                DateModified  = DateTime.Now
            };

            await new BLL.SectionItem(unitOfWork).Edit(si);

            // Update Photo
            IFormFile uploadedImage = file;

            if (uploadedImage != null && uploadedImage.ContentType.ToLower().StartsWith("image/"))
            {
                var bsectionitemphoto  = new BLL.SectionItemPhoto(unitOfWork);
                var bsectionitemphotos = await bsectionitemphoto.Find(new EF.SectionItemPhoto {
                    SectionItemId = args.SectionItemId
                });

                if (bsectionitemphotos.Count() > 0)
                {
                    await new BLL.Photo(unitOfWork).Delete(bsectionitemphotos.First().PhotoId, _environment);
                }

                var pid = await new BLL.Photo(unitOfWork).Add(_environment, file);

                var sip = new EF.SectionItemPhoto();
                sip.SectionItemId = id1;
                sip.PhotoId       = pid;
                await bsectionitemphoto.Edit(sip);
            }


            foreach (var rec in props)
            {
                if (rec.Value != null)
                {
                    if (rec.SectionItemId != 0)
                    {
                        // Update SectionItemProperty
                        var sipr = new EF.SectionItemProperty
                        {
                            SectionItemId     = id1,
                            SectionPropertyId = rec.SectionPropertyId,
                            Value             = rec.Value
                        };
                        await new BLL.SectionItemProperty(unitOfWork).Edit(sipr);
                    }
                    else
                    {
                        // Add SectionItemProperty
                        var sipr = new EF.SectionItemProperty();
                        sipr.SectionItemId     = args.SectionItemId;
                        sipr.SectionPropertyId = rec.SectionPropertyId;
                        sipr.Value             = rec.Value;
                        await new BLL.SectionItemProperty(unitOfWork).Add(sipr);
                    }
                }
                else
                {
                    // Delete SectionItemProperty
                    var bsip = new BLL.SectionItemProperty(unitOfWork);

                    var sipr = await bsip.Get(new EF.SectionItemProperty {
                        SectionItemId = args.SectionItemId, SectionPropertyId = rec.SectionPropertyId
                    });

                    if (sipr != null)
                    {
                        await bsip.Delete(sipr);
                    }
                }
            }

            return(Redirect("~/Section/" + id + "/Items"));
        }