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

            model.CreatedBy = User.Identity.Name;

            var bevent = new BLL.Event(unitOfWork);

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

            var id = await bevent.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 ep = new EF.EventPhoto();
                ep.EventId = id;
                ep.PhotoId = pid;
                await new BLL.EventPhoto(unitOfWork).Add(ep);
            }

            return(Redirect("~/Main/Event"));
        }
예제 #2
0
        public async Task <IActionResult> Edit([Bind(Prefix = "Item1")] EF.Event model, [Bind(Prefix = "Item2")] bool isactive, IFormFile file)
        {
            ViewData["Title"] = "Event/Edit";

            model.ModifiedBy = User.Identity.Name;

            var bevent = new BLL.Event(unitOfWork);

            // Update Event
            if (!isactive)
            {
                model.DateInactive = DateTime.Now;
            }
            else
            {
                model.DateInactive = null;
            }

            await bevent.Edit(model);

            // Update Photo
            IFormFile uploadedImage = file;

            if (uploadedImage != null && uploadedImage.ContentType.ToLower().StartsWith("image/"))
            {
                var beventphoto = new BLL.EventPhoto(unitOfWork);
                var eventphotos = await beventphoto.Find(new EF.EventPhoto {
                    EventId = model.EventId
                });

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

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

                var ep = new EF.EventPhoto();
                ep.EventId = model.EventId;
                ep.PhotoId = pid;
                await beventphoto.Edit(ep);
            }

            return(Redirect("~/Main/Event"));
        }