Esempio n. 1
0
        public async Task <IActionResult> Update(string moniker, int id, [FromBody] TimeSlot model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var eventInfo = await _repo.GetEventInfoAsync(moniker);

                    if (eventInfo != null)
                    {
                        var slot = await _repo.GetTimeSlotAsync(moniker, id);

                        if (slot == null || slot.Id != id)
                        {
                            return(BadRequest());
                        }

                        slot.Time = model.Time.ToLocalTime();

                        await _repo.SaveChangesAsync();

                        return(Ok(slot));
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError("Failed to update a timeslot: {0}", ex);
                }
            }

            return(BadRequest("Failed to update TimeSlot"));
        }