public async Task<HttpResponseMessage> Create(CreateDto dto) { //Contract.Requires<ArgumentNullException>(dto != null); try { dto.OwnerId = Guid.Parse("e0aed236-3177-4ff7-9a39-25bb16c8ed62"); dto.OthersToRemind = await _connectionsService.Create(dto.OthersToRemind); await _connectionsService.UpdateReferencedConnections(dto.OwnerId, dto.OthersToRemind); var newReminders = await _remindersService.Create(dto); return Request.CreateResponse(HttpStatusCode.OK, newReminders); } catch (Exception e) { Console.WriteLine(e); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message); } }
public async Task<List<ReminderDto>> Create(CreateDto dto) { var newReminders = new List<ReminderDto>(); var reminderConnections = dto.OthersToRemind.Select(Mapper.Map<ReminderConnectionDto, ReminderConnection>).ToList(); for(var i = 1; i <= dto.Occurrences; i++ ) { var newReminder = Mapper.Map<CreateDto, Reminder>(dto); newReminder.Date = CalculateOccurrenceDate(dto.Date, i, dto.Frequency); newReminder.OthersToRemind = reminderConnections; await _remindersRepository.Create(newReminder); var mappedDto = Mapper.Map<Reminder, ReminderDto>(newReminder); newReminders.Add(mappedDto); } return newReminders.OrderByDescending(x => x.Date).ToList(); }