Esempio n. 1
0
        public async Task <IActionResult> Put(int id, [FromBody] EventViewModel value)
        {
            EventViewModel result = null;

            if (ModelState.IsValid)
            {
                result = (await eventService.UpdateAsync(value.ToDto())).ToViewModel();
            }

            return(Accepted(result));
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] EventViewModel value)
        {
            EventViewModel result = null;

            if (ModelState.IsValid)
            {
                var exist  = false;
                var events = await eventService.GetAllAsync();

                events.ToList().ForEach(element =>
                {
                    if (element.EntryDate == value.EntryDate)
                    {
                        exist = true;
                    }
                });
                if (!exist)
                {
                    result = (await eventService.AddAsync(value.ToDto())).ToViewModel();
                    return(Created("{id}", result));
                }
            }
            return(BadRequest());
        }