Exemplo n.º 1
0
        public IActionResult Post([FromBody] TimelineEventViewModel timelineEvent)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var newEvent = Mapper.Map <TimelineEvent>(timelineEvent);

                    //Save to the database
                    _logger.LogInformation("Attempting to save a new event");
                    _repo.AddOrUpdateTimelineEvent(newEvent);

                    Response.StatusCode = (int)HttpStatusCode.Created;
                    return(Json(Mapper.Map <TimelineEventViewModel>(newEvent)));
                }
                catch (Exception ex)
                {
                    _logger.LogError("Failed to Save new event", ex);
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Json(new { Message = ex.Message }));
                }
            }

            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Json(new { Message = "Failed to Save new event", ModelState = ModelState }));
        }
        public ActionResult Create(string timelineId)
        {
            var vm = new TimelineEventViewModel
            {
                EventDateTime = DateTime.Now
            };

            return(PartialView(vm));
        }
        public ActionResult Edit(string timelineId, string eventId)
        {
            TimelineEvent timelineEvent = _repo.GetTimelineEvent(eventId);

            var vm = new TimelineEventViewModel
            {
                Title         = timelineEvent.Title,
                Description   = timelineEvent.Description,
                EventDateTime = timelineEvent.EventDateTime,
                Location      = timelineEvent.Location
            };

            return(PartialView(vm));
        }
        public async Task <ActionResult> Edit(string timelineId, string eventId, [Bind("Title,Description,EventDateTime")]  TimelineEventViewModel vm)
        {
            if (ModelState.IsValid)
            {
                TimelineEvent evt = _repo.GetTimelineEvent(eventId);
                evt.Title         = vm.Title;
                evt.EventDateTime = vm.EventDateTime;
                evt.Description   = vm.Description;
                await _repo.EditTimelineEventAsync(evt);

                _flash.Message($"Event '{evt.Title}' edited!");

                return(Ok("OK " + evt.Id));
            }

            return(PartialView(vm));
        }
        public async Task <ActionResult> Create(string timelineId, [Bind("Title,Description,EventDateTime")] TimelineEventViewModel vm)
        {
            if (ModelState.IsValid)
            {
                TimelineEvent evt = await _repo.CreateTimelineEventAsync(
                    vm.Title,
                    vm.Description,
                    vm.EventDateTime,
                    vm.Location,
                    timelineId);

                _flash.Message($"Event '{evt.Title}' added!");

                return(Ok("OK " + evt.Id));
            }

            return(PartialView(vm));
        }