public ActionResult ModifyEvents(EventModel model, string StartTime, string EndTime, DateTime NewDate)
        {
            ModifyEventViewModel model2 = new ModifyEventViewModel();
            int startMin;
            int startHour;
            int endMin;
            int endHour;

            string[] split = StartTime.Split(new char[] { ':', ' ' });
            startMin = Int32.Parse(split[1]);

            if (split[2].Equals("PM") & !split[2].Equals("12"))
            {
                startHour = Int32.Parse(split[0]) + 12;
            }
            else if (split[2].Equals("AM") && split[2].Equals("12"))
            {
                startHour = 24;
            }
            else
            {
                startHour = Int32.Parse(split[0]);
            }

            string[] split2 = EndTime.Split(new char[] { ':', ' ' });
            endMin = Int32.Parse(split2[1]);

            if (split2[2].Equals("PM") & !split2[2].Equals("12"))
            {
                endHour = Int32.Parse(split2[0]) + 12;
            }
            else if (split2[2].Equals("AM") && split2[2].Equals("12"))
            {
                endHour = 24;
            }
            else
            {
                endHour = Int32.Parse(split2[0]);
            }
            model.StartMin = startMin;
            model.StartHour = startHour;
            model.EndMin = endMin;
            model.EndHour = endHour;
            model.Day = NewDate.Day;
            model.Month = NewDate.Month;
            model.Year = NewDate.Year;

            //uvModel.GetEventsCreatedBy((int)Session["UserId"]);
            model.ChangeEventDetails(model);
            model2.GetEventsCreatedBy((int)Session["UserId"]);

            return View("ModifyEvents", model2);
        }
        public ActionResult ModifyEvents()
        {
            if (Session["UserId"] == null || (int)Session["UserId"] == 0)
            {
                ViewData["ErrorMessage"] = "You must be signed in to view this data";
                return Redirect("~/Account/Login");
            }

            ModifyEventViewModel model = new ModifyEventViewModel();
            model.GetEventsCreatedBy((int)Session["UserId"]);

            return View("ModifyEvents", model);
        }
Beispiel #3
0
        public IActionResult Put(int id, [FromBody] ModifyEventViewModel editedEvent)
        {
            if (ModelState.IsValid)
            {
                if (!IsMerchant())
                {
                    return(BadRequest(new { error = "De voorziene token voldoet niet aan de eisen." }));
                }

                Event eventFromDb = _eventRepository.getById(id);

                if (eventFromDb == null)
                {
                    return(BadRequest(new { error = "Evenement niet gevonden." }));
                }

                if (!_eventRepository.isOwnerOfEvent(int.Parse(User.FindFirst("userId")?.Value), id))
                {
                    return(BadRequest(new { error = "Evenement behoord niet tot uw evenementen." }));
                }

                if (!string.IsNullOrEmpty(editedEvent.Name))
                {
                    eventFromDb.Name = editedEvent.Name;
                }

                if (!string.IsNullOrEmpty(editedEvent.Message))
                {
                    eventFromDb.Message = editedEvent.Message;
                }

                if (editedEvent.StartDate != null)
                {
                    eventFromDb.StartDate = (DateTime)editedEvent.StartDate;
                }

                if (editedEvent.EndDate != null)
                {
                    eventFromDb.EndDate = (DateTime)editedEvent.EndDate;
                }

                if (editedEvent.Images != null && editedEvent.Images.Any())
                {
                    var images = ConvertFileViewModelToImages(editedEvent.Images, id);
                    if (images.Any())
                    {
                        eventFromDb.Images = images;
                    }
                }

                if (editedEvent.Attachments != null && editedEvent.Attachments.Any())
                {
                    var attachments = ConvertFileViewModelToAttachments(editedEvent.Attachments, id);
                    if (attachments.Any())
                    {
                        eventFromDb.Attachments = attachments;
                    }
                }

                _eventRepository.SaveChanges();
                return(Ok(new { bericht = "Het evenement werd succesvol bijgewerkt." }));
            }
            //Als we hier zijn is is modelstate niet voldaan dus stuur error 400, slechte aanvraag
            string errorMsg = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));

            return(BadRequest(new { error = errorMsg }));
        }