예제 #1
0
        public CalendersDto PostCalenders(CalendersDto calendersDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var calender = Mapper.Map <CalendersDto, Calenders>(calendersDto);

            _context.Calenders.Add(calender);
            _context.SaveChanges();

            return(calendersDto);
        }
예제 #2
0
        public void PutCalenders(int calendersId, CalendersDto calendersDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var calender = _context.Calenders.SingleOrDefault(c => c.CalendersId == calendersId);

            if (calender == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Mapper.Map(calendersDto, calender);

            _context.SaveChanges();
        }