public IActionResult AddingActivity(ActivityForm form, Activity newActivity)
 {
     if (ModelState.IsValid)
     {
         int activityDate = form.Date.DayOfYear;
         int Today        = DateTime.Now.DayOfYear;
         if (activityDate < Today)
         {
             ModelState.AddModelError("Date", "Must create an activity for a future date.");
             return(View("CreateActivity"));
         }
         int?     idUser       = HttpContext.Session.GetInt32("LoggedID");
         DateTime activityDay  = form.Date;
         TimeSpan activityTime = form.Time;
         newActivity.Date   = activityDay + activityTime;
         newActivity.UserId = (int)idUser;
         string HMD = form.HMD;
         newActivity.Duration = form.Duration + " " + HMD;
         dbContext.Add(newActivity);
         dbContext.SaveChanges();
         // SELECTING ADDED Activity ID
         Activity thisActivityId = dbContext.Activities
                                   .Where(w => w.ActivityId == newActivity.ActivityId)
                                   .SingleOrDefault();
         return(RedirectToAction("ActivityInfo", new { activityId = thisActivityId.ActivityId }));
     }
     return(View("CreateActivity"));
 }
        public IActionResult EditToDB(ActivityForm FormData, int id)
        {
            if (!HttpContext.Session.Keys.Contains("user"))
            {
                return(RedirectToAction("Logout", "User"));
            }
            if (!ModelState.IsValid)
            {
                return(View("EditActivity"));
            }
            User host = dbContext.Users
                        .SingleOrDefault(u =>
                                         u.UserID == HttpContext.Session.GetInt32("user"));

            DojoActivity editActivity = dbContext.DojoActivitys
                                        .SingleOrDefault(u =>
                                                         u.DojoActivityID == id);

            editActivity.DojoActivityMessage = FormData.Message;
            editActivity.CreatedAt           = DateTime.Now;
            editActivity.UpdatedAt           = DateTime.Now;
            editActivity.UserID = host.UserID;
            dbContext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
Example #3
0
        public IActionResult DisplayToDB(ActivityForm FormData)
        {
            if (!HttpContext.Session.Keys.Contains("user"))
            {
                return(RedirectToAction("Logout", "User"));
            }
            if (!ModelState.IsValid)
            {
                return(View("NewActivity"));
            }
            User host = dbContext.Users
                        .SingleOrDefault(u =>
                                         u.UserID == HttpContext.Session.GetInt32("user"));

            DojoActivity newActivity = new DojoActivity();

            //     WedderOne = FormData.WedderOne,
            //     WedderTwo = FormData.WedderTwo,
            //     Date = FormData.Date,
            //     Address = FormData.Address
            // };

            newActivity.DojoActivityName = FormData.Title;
            newActivity.Time             = FormData.Time;
            newActivity.Date             = FormData.Date;
            newActivity.Duration         = FormData.Duration;
            newActivity.Description      = FormData.Description;
            newActivity.CreatedAt        = DateTime.Now;
            newActivity.UpdatedAt        = DateTime.Now;
            newActivity.UserID           = host.UserID;
            dbContext.DojoActivitys.Add(newActivity);
            dbContext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
 public virtual JsonResult Put(int number, ActivityForm model)
 {
     var command = new UpdateMyActivityCommand
     {
         Principal = User,
         Number = number,
     };
     if (model.Mode == ActivityMode.Protected)
         model.Mode = ActivityMode.Public;
     Mapper.Map(model, command);
     _services.UpdateCommandHandler.Handle(command);
     var message = ModelState.IsValid ? SuccessMessage : null;
     return Json(message);
 }
        public virtual JsonResult Draft(int number, ActivityForm model)
        {
            var command = new DraftMyActivityCommand
            {
                Principal = User,
                Number    = number,
            };

            if (model.Mode == ActivityMode.Protected)
            {
                model.Mode = ActivityMode.Public;
            }
            Mapper.Map(model, command);
            _services.DraftCommandHandler.Handle(command);
            return(Json(null));
        }
        public virtual JsonResult Put(int number, ActivityForm model)
        {
            var command = new UpdateMyActivityCommand
            {
                Principal = User,
                Number    = number,
            };

            if (model.Mode == ActivityMode.Protected)
            {
                model.Mode = ActivityMode.Public;
            }
            Mapper.Map(model, command);
            _services.UpdateCommandHandler.Handle(command);
            var message = ModelState.IsValid ? SuccessMessage : null;

            return(Json(message));
        }
Example #7
0
        public IActionResult Create_Event(ActivityForm InboundEvent)
        {
            var  LoggedinUserId = HttpContext.Session.GetInt32("UserId") ?? 0;
            User LoggedInUser   = dbContext.Users.FirstOrDefault(u => LoggedinUserId == u.UserId);

            ViewBag.User        = LoggedInUser;
            InboundEvent.UserId = LoggedInUser.UserId;
            if (ModelState.IsValid)
            {
                if (InboundEvent.DateAndTime < DateTime.Now)
                {
                    ModelState.AddModelError("DateAndTime", "Please select a date and time in the future.");
                    return(View("NewActivity"));
                }
                Event createEvent = new Event()
                {
                    Name        = InboundEvent.Name,
                    Duration    = InboundEvent.Duration + InboundEvent.Duration2,
                    DateAndTime = InboundEvent.DateAndTime,
                    Description = InboundEvent.Description,
                    UserId      = InboundEvent.UserId,
                    Creator     = InboundEvent.Creator,
                };
                dbContext.Events.Add(createEvent);
                dbContext.SaveChanges();
                System.Console.WriteLine("Added new Event,", InboundEvent.Name);
                int EventId = createEvent.EventId;
                return(RedirectToAction("ViewEvent", new{ EventId = EventId }));
                // }
            }
            else
            {
                // var LoggedinUserID = HttpContext.Session.GetInt32("UserId") ?? 0;
                // User LoggedInUseR = dbContext.Users.FirstOrDefault(u => LoggedinUserId == u.UserId);
                // ViewBag.User = LoggedInUseR.UserId;
                System.Console.WriteLine("Moving to else statement, model didn't validate");
                return(View("NewActivity"));
            }
        }
 public virtual JsonResult Draft(int number, ActivityForm model)
 {
     var command = new DraftMyActivityCommand
     {
         Principal = User,
         Number = number,
     };
     if (model.Mode == ActivityMode.Protected)
         model.Mode = ActivityMode.Public;
     Mapper.Map(model, command);
     _services.DraftCommandHandler.Handle(command);
     return Json(null);
 }