public async Task <Day> UpdateDay(int userId, DayUpdateDTO newDay) { //var userWs = await GetUserWS(userId); var day = await _context.Day .Where(x => x.FromTime.DayOfYear == newDay.FromTime.DayOfYear) .FirstOrDefaultAsync(x => x.IdWsNavigation.IdUser == userId); day.FromTime = Convert.ToDateTime(newDay.FromTime); day.ToTime = Convert.ToDateTime(newDay.ToTime); day.Type = newDay.Type; _context.Day.Update(day); await _context.SaveChangesAsync(); return(day); }
public async Task <IActionResult> EditDayInWS(int id, DayUpdateDTO day) { if (await _userRepo.GetUser(id) == null) { return(Content("Brak usera o podanym id")); } if (await _wsRepo.CheckIfDayExists(id, day.FromTime) == null) { return(Content($"Brak grafika w dniu {day.FromTime.Date} dla użytkownika o id {id}")); } var updatedDay = await _wsRepo.UpdateDay(id, day); var dayToReturn = _mapper.Map <DayNewDTO>(updatedDay); return(Ok(dayToReturn)); }