예제 #1
0
        public async Task <IActionResult> Page([FromBody] EF.Event obj, int id)
        {
            var bll_event = eventBusiness;
            var user      = HttpContext.Items["EndUser"] as EF.EndUser;

            obj.EventCategory = new EF.EventCategory {
                CommunityId = user.Member.CommunityId
            };

            var res = from r in bll_event.Find(obj)
                      select new
            {
                r.Id,
                r.EventCategoryId,
                Category = r.EventCategory.Name,
                r.Name,
                r.IsActive,
                r.DateTimeStart,
                Location   = (r.Location == null ? "" : r.Location.Name),
                Attendance = r.Attendance.Count,
                r.IsExclusive
            };
            var page  = id;
            var pager = new Core.Pager(await res.CountAsync(), page == 0 ? 1 : page, 100);

            dynamic obj1 = new ExpandoObject();

            obj1.events = await res.Skip((pager.CurrentPage - 1) *pager.PageSize).Take(pager.PageSize).ToListAsync();

            obj1.pager = pager;

            return(Json(obj1));
        }
예제 #2
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"));
        }
예제 #3
0
        public async Task <IActionResult> Download([FromBody] EF.Event obj)
        {
            var bll_event = eventBusiness;
            var user      = HttpContext.Items["EndUser"] as EF.EndUser;

            obj.EventCategory = new EF.EventCategory {
                CommunityId = user.Member.CommunityId
            };

            var res = from r in (await bll_event.Find(obj).ToListAsync())
                      select new
            {
                r.Id,
                r.EventCategoryId,
                Category = r.EventCategory.Name,
                r.Name,
                r.IsActive,
                r.DateTimeStart,
                Location   = (r.Location == null ? "" : r.Location.Name),
                Attendance = r.Attendance.Count,
                r.IsExclusive
            };

            var bytes = Encoding.ASCII.GetBytes(res.ToList().ExportToCsv().ToString());

            var result = new FileContentResult(bytes, "text/csv");

            result.FileDownloadName = "my-csv-file.csv";
            return(result);
        }
예제 #4
0
        public async Task <IActionResult> Find([FromBody] EF.Event obj)
        {
            var bll_event = eventBusiness;
            var user      = HttpContext.Items["EndUser"] as EF.EndUser;

            obj.EventCategory = new EF.EventCategory {
                CommunityId = user.Member.CommunityId
            };

            var res = from r in (await bll_event.Find(obj).ToListAsync())
                      select new
            {
                r.Id,
                r.EventCategoryId,
                Category = r.EventCategory.Name,
                r.Name,
                r.IsActive,
                r.DateTimeStart,
                Location   = (r.Location == null ? "" : r.Location.Name),
                Attendance = r.Attendance.Count,
                r.IsExclusive
            };

            return(Json(res));
        }
예제 #5
0
        public async Task <int> Add(EF.Event args)
        {
            args.IsActive = true;
            await unitOfWork.EventRepository.AddAsync(args);

            unitOfWork.Commit();
            return(args.Id);
        }
예제 #6
0
 public async Task <EF.Event> Get(EF.Event args)
 {
     return(await unitOfWork.EventRepository.Entities
            .Include(x => x.EventCategory)
            .Include(x => x.Attendance).ThenInclude(x => x.FirstTimer)
            .Include(x => x.Location)
            .FirstOrDefaultAsync(x => x.Id == args.Id &&
                                 x.EventCategory.CommunityId == args.EventCategory.CommunityId));
 }
예제 #7
0
        public async Task Edit([FromBody] EF.Event obj)
        {
            var bll_event = eventBusiness;
            var user      = HttpContext.Items["EndUser"] as EF.EndUser;

            obj.EventCategory = new EF.EventCategory {
                CommunityId = user.Member.CommunityId
            };

            await bll_event.Edit(obj);
        }
예제 #8
0
        public async Task Edit(EF.Event args)
        {
            var e = await unitOfWork.EventRepository.Entities.FirstAsync(x => x.Id == args.Id &&
                                                                         x.EventCategory.CommunityId == args.EventCategory.CommunityId);

            e.Name            = args.Name;
            e.LocationId      = args.LocationId;
            e.EventCategoryId = args.EventCategoryId;
            e.DateTimeStart   = args.DateTimeStart;

            unitOfWork.Commit();
        }
예제 #9
0
 public IQueryable <EF.Event> Find(EF.Event args)
 {
     return(unitOfWork.EventRepository.Entities
            .Include(x => x.EventCategory)
            .Include(x => x.Attendance)
            .Include(x => x.Location)
            .Where(x => (x.DateTimeStart >= (args.DateTimeStart ?? x.DateTimeStart) && x.DateTimeStart <= (args.DateTimeEnd ?? DateTime.Now.AddYears(100))) &&
                   x.Name.Contains(args.Name ?? "") &&
                   x.EventCategoryId == (args.EventCategoryId == 0 ? x.EventCategoryId : args.EventCategoryId) &&
                   x.LocationId == ((args.LocationId ?? 0) == 0 ? x.LocationId : args.LocationId) &&
                   x.EventCategory.CommunityId == args.EventCategory.CommunityId)
            .OrderByDescending(x => x.DateTimeStart).AsQueryable());
 }
예제 #10
0
        public void EditEvent_Failed(EF.Event args)
        {
            var completed = false;

            mockUnitOfWork.Setup(x => x.Commit()).Callback(() =>
            {
                completed = true;
            });

            eventBusiness.Edit(args);

            Assert.True(!completed);
        }
예제 #11
0
        public void AddEvent_Success(EF.Event args)
        {
            var list  = mockEventRepo.Object.Entities.ToList();
            var count = list.Count();

            mockUnitOfWork.Setup(x => x.Commit()).Callback(() =>
            {
                list.Add(args);
            });

            var id = eventBusiness.Add(args).Result;

            Assert.True(list.Count > count);
        }
예제 #12
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"));
        }
예제 #13
0
 public async Task <IActionResult> Index(EF.Event args)
 {
     ViewData["Title"] = "Events";
     ViewBag.Data      = await new BLL.Event(unitOfWork).Find(args);
     return(View());
 }
예제 #14
0
 public Task Delete(EF.Event args)
 {
     throw new NotImplementedException();
 }
예제 #15
0
        public void FindEvent_NoResult(EF.Event args)
        {
            var res = eventBusiness.Find(args);

            Assert.True(res.Count() == 0);
        }