public async Task <IActionResult> Post([FromBody] CreateCalendarModel model) { if (model is null) { throw new ApiException("Model is null.", StatusCodes.Status400BadRequest); } var entity = _mapper.Map <CreateCalendarModel, Calendar>(model); entity.Code = CodeHelper.GetCode(); User user = await _userManager.GetUserAsync(HttpContext.User); entity.Creator = user; _repository.Add(entity); await _unitOfWork.CompleteAsync(); if (user != null) { await _unitOfWork.Users.AddUserCalendarAsync(user.Id, entity.Id); } return(Ok(_mapper.Map <Calendar, CalendarModel>(entity))); }
public void NewEvents(CalendarEvent theEvent) { var caller = Context.ConnectionId; var data = theEvent; if (data.description == null) data.description = "all"; var obj = CalendarEvent.ToDatabase(data); _db.Add(obj as CalEvent); _db.Save(); data = CalendarEvent.FromDatabase(obj); if (data.description != "all") { Clients.Group(data.description).newEvent(data); try { Clients.Group(data.description + "#" + data.title).newEvent(data); } catch (Exception e) { Clients.Caller.logger(e.Message, 2); } Clients.Group("all").newEvent(data); } else { Clients.All.newEvent(data); } }
public async Task <Unit> Handle(AddNurseToCalendarCommand request, CancellationToken cancellationToken) { //var doctor = await _medicalRepository.GetByIdAsync(new MedicalStuffId(request.DoctorId)); var doctor = await _medicalRepository.GetById(new MedicalStuffId(request.DoctorId)); //var calendar = await _calendarRepository.GetByIdAsync(doctor.GetCalendarId()); var calendar = await _calendarRepository.GetById(doctor.GetCalendarId()); //calendar.AddAccesToCalendar(new MedicalStuffId(request.NurseId)); calendar.AddAccesToCalendar(new MedicalStuffId(request.NurseId)); await _calendarRepository.Add(calendar); //await _calendarRepository.Save(); return(Unit.Value); }
public async Task <Guid> Handle(CreateDoctorCommand request, CancellationToken cancellationToken) { var clinic = await _clinicRepository.GetByIdAsync(new ClinicId(request.ClinicId)); var nursesIds = request.NursesIds.Select(x => new MedicalStuffId(x)).ToList(); var calendar = new Calendar($"{request.Firstname}'s Calendar", nursesIds); await _calendarRepository.Add(calendar); var doctor = clinic.AddNewDoctor(request.Firstname, request.Lastname, request.DateOfBirth, calendar.Id); await _medicalRepository.AddAsync(doctor); await _calendarRepository.Save(); await _medicalRepository.Save(); return(doctor.Id.Value); }
public async Task <IActionResult> PostAbsenceRequest([FromBody] AbsenceRequestCreateDto absenceRequestCreateDto) { //todo: validation (dates not in past etc.) if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newAbsenceRequest = new AbsenceRequest() { CreatedAt = DateTime.UtcNow, FromDate = absenceRequestCreateDto.FromDate, ToDate = absenceRequestCreateDto.ToDate, State = AbsenceRequestState.Requested, UserId = GetCurrentUserId() }; _repo.Add(newAbsenceRequest); try { await _repo.Save(); } catch (DbUpdateException) { if (await AbsenceRequestExists(newAbsenceRequest.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetAbsenceRequest", new { id = newAbsenceRequest.Id }, _mapper.Map <AbsenceRequestDto>(newAbsenceRequest))); }
public async Task <bool> Handle(CreateCalendarCommand command, CancellationToken cancellationToken) { var property = await _propertyRepository.GetAsync(command.PropertyId); if (property == null) { throw new FantasticStayDomainException($"Cannot find property with id '{command.PropertyId}'."); } var calendar = await _calendarRepository.GetByPropertyAsync(property.Id); if (calendar != null) { return(true); } calendar = new Calendar(property.Id); _logger.LogInformation("Creating Calendar - {@Calendar}", calendar); _calendarRepository.Add(calendar); return(await _calendarRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)); }
public async Task CreateEvent(CalendarEventModel model) { model.Id = Guid.NewGuid(); var calendarEvent = Mapper.Map <CalendarEvent>(model); await _repository.Add(calendarEvent); }
public void Add(CalendarOfEvents obj) { _repository.Add(obj); }
public async Task <IActionResult> Post([FromBody] string name) { return(Ok(await _calendarRepository.Add(name))); }