Esempio n. 1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                Domain.Activity activity = await _context.Activities.FindAsync(request.Id);

                if (activity == null)
                {
                    throw new Exception("Could not find activity.");
                }

                activity.Title       = request.Title ?? activity.Title;
                activity.Description = request.Description ?? activity.Description;
                activity.Category    = request.Category ?? activity.Category;
                activity.Date        = request.Date ?? activity.Date;
                activity.City        = request.City ?? activity.City;
                activity.Venue       = request.Venue ?? activity.Venue;

                bool success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes.");
            }
Esempio n. 2
0
 public virtual string FormatActivity(Domain.Activity activity, bool includeHeader, bool includeSummary)
 {
     return(string.Format("{0}\t{1}\t{2}\t{3}",
                          activity.Name,
                          string.Join(" ", (activity.Tags ?? Enumerable.Empty <ActivityTag>()).Select(t => t.Name).ToArray()),
                          activity.ExpectedEffort,
                          activity.ActualEffort));
 }
Esempio n. 3
0
        public ActionResult CreateMany(int id)
        {
            Domain.Activity firstAct = serv.Get(id);
            var             m        = map.Map <Domain.Activity, ViewModel.ActivitySchedule>(firstAct);

            m.def = def;
            return(PartialView("CreateMany", m));
        }
Esempio n. 4
0
 public JsonResult Edit(int id, FormCollection collection, string userName)
 {
     Domain.Activity activity = serv.Get(id);
     UpdateModel(activity);
     serv.Save(activity, userName);
     return(Json(new
     {
         jobSuccess = true
     }, JsonRequestBehavior.AllowGet));
 }
Esempio n. 5
0
 public Activity(Domain.Activity t)
 {
     this.Id           = t.Id;
     this.Notes        = t.Notes;
     this.PerformedOn  = t.PerformedOn;
     this.ScheduledOn  = t.ScheduledOn;
     this.ActivityType = t.ActivityType.Name;
     this.Quantity     = t.Quantity;
     this.Points       = t.Points;
     this.User         = UserProfile.Button(t.CreatedByUser.Id, t.CreatedByUser.Name);
 }
        private void ScheduleActivity(string Args, int time)
        {
            Domain.Activity activity = new Domain.Activity
            {
                Name          = "shutdown",
                Arguments     = Args,
                ScheduledTime = DateTime.Now,
                DueTime       = DateTime.Now.AddSeconds(time),
                User          = User,
                Guild         = Guild
            };

            Database.Activities.Add(activity);
        }
        private async Task AddActors(Activity activity)
        {
            if (activity.Actors == null || !activity.Actors.Any())
            {
                return;
            }

            foreach (var actor in activity.Actors)
            {
                actor.ActivityId = activity.Id;
                var persistedActor = await _actorService.Add(actor);

                actor.Id = persistedActor.Id;
            }
        }
        private async Task AddNestedActivities(Activity activity)
        {
            if (activity.Activities == null || !activity.Activities.Any())
            {
                return;
            }

            foreach (var child in activity.Activities)
            {
                child.ParentId = activity.Id;
                var persistedChild = await Add(child);

                child.Id = persistedChild.Id;
            }
        }
        private async Task AddActions(Activity activity)
        {
            if (activity.Actions == null || !activity.Actions.Any())
            {
                return;
            }

            foreach (var action in activity.Actions)
            {
                action.ActivityId = activity.Id;
                var persistedAction = await _actionService.Add(action);

                action.Id = persistedAction.Id;
            }
        }
Esempio n. 10
0
        public JsonResult Create(Domain.Activity activ, string userName)
        {
            UpdateModel(activ);
            activ.firstID = activ.ID;

            if (activ.nameID == 0)
            {
                if (activ.typeID == lcache.getByKeys(LCategory.activityType, LActType.Assembly))
                {
                    activ.nameID = lcache.getByKeys(LCategory.activityName, LActName.Assembly);
                }
                else if (activ.typeID == lcache.getByKeys(LCategory.activityType, LActType.OrgMtg))
                {
                    activ.nameID = lcache.getByKeys(LCategory.activityName, LActName.OrgMtg);
                }
                else
                {
                    throw new MacheteIntegrityException("Something went wrong with Activity Types.");
                }
            }

            if (activ.dateEnd < activ.dateStart)
            {
                return(Json(new { jobSuccess = false, rtnMessage = "End date must be greater than start date." }));
            }

            Domain.Activity firstAct = serv.Create(activ, userName);
            var             result   = map.Map <Domain.Activity, ViewModel.Activity>(firstAct);

            if (activ.recurring == true)
            {
                result.tablabel = "Recurring event with " + firstAct.teacher;
                result.tabref   = "/Activity/CreateMany/" + Convert.ToString(firstAct.ID);
            }


            return(Json(new
            {
                sNewRef = result.tabref,
                sNewLabel = result.tablabel,
                iNewID = result.ID,
                jobSuccess = true
            }));
        }
        public async Task <Activity> Add(Activity activity)
        {
            if (!_addActivityValidator.IsValidForAdd(activity))
            {
                throw new Exception();
            }

            var request  = _requestBuilder.BuildAddActivityRequest(activity);
            var response = await _restClient.ExecuteTaskAsync <ApiActivity>(request);

            _responseValidator.Validate(response);
            activity.Id = response.Data.Id;

            await AddNestedActivities(activity);
            await AddActors(activity);
            await AddActions(activity);

            return(_activityConvertor.Convert(response.Data));
        }
Esempio n. 12
0
        public JsonResult DeleteMany(int id, string userName)
        {
            Domain.Activity firstToDelete = serv.Get(id);
            List <int>      allToDelete   = serv.GetAll()
                                            .Where(w => w.firstID == firstToDelete.firstID && w.dateStart >= firstToDelete.dateStart)
                                            .Select(s => s.ID).ToList();

            foreach (int toDelete in allToDelete)
            {
                serv.Delete(toDelete, userName);
            }

            return(Json(new
            {
                status = "OK",
                jobSuccess = true,
                deletedID = id
            },
                        JsonRequestBehavior.AllowGet));
        }
Esempio n. 13
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                Domain.Activity activity = await _context.Activities.FindAsync(request.Id);

                if (activity == null)
                {
                    throw new Exception("Could not find activity");
                }

                _context.Remove(activity);

                bool success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes.");
            }
Esempio n. 14
0
            //return Unit, not anything to do with activity
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                //compose activity
                var activity = new Domain.Activity
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Description = request.Description,
                    Category    = request.Category,
                    Date        = request.Date,
                    City        = request.City,
                    Venue       = request.Venue
                };

                //add activity to DB
                _context.Add(activity);

                //get user from DB
                var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUserName());

                //create attendee - notice AppUserId and ActivityId are not required
                var attendee = new Domain.UserActivity {
                    AppUser    = user,
                    Activity   = activity,
                    DateJoined = DateTime.Now,
                    IsHost     = true
                };

                //add attendee to database
                _context.UserActivities.Add(attendee);

                //SaveChangesAsync returns and int, so we check to make sure that at least one change has occured
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes.");
            }
Esempio n. 15
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = new Domain.Activity
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Description = request.Description,
                    Category    = request.Category,
                    Date        = request.Date,
                    City        = request.City,
                    Venue       = request.Venue
                };

                context.Activities.Add(activity);
                var success = await context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
Esempio n. 16
0
        public JsonResult CreateMany(ActivitySchedule actSched, string userName)
        {
            UpdateModel(actSched); // copy values from form to object. why this is necessary if the object is being passed as arg, I don't know.
            Domain.Activity firstActivity = serv.Get(actSched.firstID);
            var             instances     = actSched.stopDate.Subtract(actSched.dateStart).Days;
            var             length        = actSched.dateEnd.Subtract(actSched.dateStart).TotalMinutes;

            for (var i = 0; i <= instances; ++i) // This should skip right over firstAct.
            {
                var date = actSched.dateStart.AddDays(i);
                var day  = (int)date.DayOfWeek;

                if (day == 0 && !actSched.sunday)
                {
                    continue;
                }
                else if (day == 1 && !actSched.monday)
                {
                    continue;
                }
                else if (day == 2 && !actSched.tuesday)
                {
                    continue;
                }
                else if (day == 3 && !actSched.wednesday)
                {
                    continue;
                }
                else if (day == 4 && !actSched.thursday)
                {
                    continue;
                }
                else if (day == 5 && !actSched.friday)
                {
                    continue;
                }
                else if (day == 6 && !actSched.saturday)
                {
                    continue;
                }
                else
                {
                    var activ = new Domain.Activity();
                    activ.nameID    = actSched.name;
                    activ.typeID    = actSched.type;
                    activ.dateStart = date;
                    activ.dateEnd   = date.AddMinutes(length);
                    activ.recurring = true;
                    activ.firstID   = firstActivity.ID;
                    activ.teacher   = actSched.teacher;
                    activ.notes     = actSched.notes;

                    Domain.Activity act = serv.Create(activ, userName);
                }
            }
            var result = map.Map <Domain.Activity, ViewModel.Activity>(firstActivity);

            return(Json(new
            {
                sNewRef = result.tabref,
                sNewLabel = result.tablabel,
                iNewID = firstActivity.ID,
                jobSuccess = true
            },
                        JsonRequestBehavior.AllowGet));
        }
Esempio n. 17
0
 public virtual string FormatActivity(Domain.Activity activity)
 {
     return(FormatActivity(activity, IncludeHeader, IncludeSummary));
 }