示例#1
0
        public ActionResult EditActivity(ActivityModel model)
        {
            ActivityModel activity = db.Activity.Find(model.Id);

            activity.Name        = model.Name;
            activity.Invitees    = model.Invitees;
            activity.TimeStart   = DateTime.Now;
            activity.TimeEnd     = DateTime.Now.AddMinutes(model.ActivityLength);
            activity.CostPerUser = model.CostPerUser;
            activity.Area        = DistanceFinder.ConvertInviteeArea(model.Area);
            db.SaveChanges();
            return(RedirectToAction("ViewActivities"));
        }
示例#2
0
        public ActionResult CreateActivity(ActivityModel model)
        {
            var           UserId      = System.Web.HttpContext.Current.User.Identity.GetUserId();
            ActivityModel newActivity = new ActivityModel();

            newActivity.Name        = model.Name;
            newActivity.CostPerUser = model.CostPerUser;
            if (model.CostPerUser == 0)
            {
                newActivity.CostPerUser = 0;
            }
            newActivity.Invitees    = model.Invitees;
            newActivity.CreatorId   = UserId;
            newActivity.Description = model.Description;
            newActivity.TimeStart   = DateTime.Now;
            newActivity.TimeEnd     = DateTime.Now.AddMinutes(model.ActivityLength);
            newActivity.Area        = DistanceFinder.ConvertInviteeArea(model.Area);
            newActivity.Active      = true;
            newActivity.Latitude    = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Latitude).First();
            newActivity.Longitude   = (from x in db.Checkin where x.UserId == UserId && x.Active == true select x.Longitude).First();
            //User can only have one created activity at a time
            try
            {
                foreach (var row in db.Activity)
                {
                    if (row.CreatorId == UserId && row.Active == true)
                    {
                        row.Active = false;
                    }
                }
            }
            catch
            { }
            //create null entries in db.UserToActivity for each invitee
            for (int i = 0; i < model.Invitees; i++)
            {
                UserToActivityModel userToActivity = new UserToActivityModel();
                userToActivity.ActivityId = model.Id;
                userToActivity.UserId     = null;
                db.UserToActivity.Add(userToActivity);
            }
            db.Activity.Add(newActivity);
            db.SaveChanges();
            return(RedirectToAction("ViewActivities"));
        }