Beispiel #1
0
        public async Task <int> AddAsync(HolidayAddModel mHoliday)
        {
            var project = _context.Projects.FirstOrDefault(c => c.ProjectId == mHoliday.ProjectId);

            if (project == null)
            {
                throw new ExpectException("Could not find Project data which ProjectId equal to " + mHoliday.ProjectId);
            }

            //Get UserInfo
            var user = _loginUser.GetLoginUserInfo();

            var model = new Holiday
            {
                ProjectId  = mHoliday.ProjectId,
                Day        = mHoliday.Day,
                Creator    = user.UserName,
                CreateDate = DateTime.Now
            };

            _context.Holidays.Add(model);
            await _context.SaveChangesAsync();

            return(model.HolidayId);
        }
        public async Task <IActionResult> AddAsync([FromBody] HolidayAddModel mHoliday)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelStateError()));
            }

            var holidayId = await _holidayRepository.AddAsync(mHoliday);

            return(CreatedAtRoute("GetByHolidayIdAsync", new { controller = "Holidays", holidayId = holidayId }, mHoliday));
        }