public ScheduleWithDateTransfer(ScheduleDto schedule, int doctorId) { DoctorId = doctorId; ActualisationDate = schedule.ActualisationDate; Monday = schedule.Monday == null ? null : new WorkDay(schedule.Monday); Tuesday = schedule.Tuesday == null ? null : new WorkDay(schedule.Tuesday); Wednesday = schedule.Wednesday == null ? null : new WorkDay(schedule.Wednesday); Thursday = schedule.Thursday == null ? null : new WorkDay(schedule.Thursday); Friday = schedule.Friday == null ? null : new WorkDay(schedule.Friday); Saturday = schedule.Saturday == null ? null : new WorkDay(schedule.Saturday); Sunday = schedule.Sunday == null ? null : new WorkDay(schedule.Sunday); IsApproved = false; }
public async Task <IActionResult> Show(long?id) { ScheduleDto schedule; if (id == null || id.Value <= 0) { schedule = new ScheduleDto(); } else { schedule = await scheduleService.GetScheduleAsync(id.Value); } return(View(schedule)); }
public void SetupHelper(ScheduleListHandler handler, SelectedScheduleDisplayHelper helper, ScheduleDto dto) { this.selectedDisplayHelper = helper; this.listHandler = handler; this.mySchedule = dto; Text[] textFields = GetComponentsInChildren <Text>(); string[] firstAndLast = dto.GetTaName().Split('_'); handleFirstAndLastNames(firstAndLast); date = dto.GetDate(); scheduleType = dto.GetScheduleType(); textFields[0].text = firstName + " " + lastName; textFields[1].text = date.Split('.')[0]; textFields[2].text = scheduleType; }
public IHttpActionResult CreateSchedule(ScheduleDto scheduleDto) { if (!ModelState.IsValid) { return(BadRequest(scheduleDto.Name)); } var schedule = Mapper.Map <ScheduleDto, Schedule>(scheduleDto); _context.Schedules.Add(schedule); _context.SaveChanges(); scheduleDto.Name = schedule.Name; return(Created(new Uri(Request.RequestUri + "/" + schedule.Name), scheduleDto)); }
public void GetRepaymentSchedule() { // Arrange LoanController controller = new LoanController(new Services.LoanService()); // Act ScheduleDto result = controller.GetRepaymentSchedule(50000, 19); // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.Installments); Assert.AreEqual(52, result.Installments.Count()); Assert.AreEqual(50000, result.Installments.ElementAt(0).AmountDue); Assert.AreEqual(875, result.Installments.ElementAt(0).Principal); }
/// <summary> /// Create a new schedule from a given day. /// Some demo settings are in place here. /// </summary> /// <param name="scheduleRequest">Parameters for the search</param> /// <returns>Scheduled shifts</returns> public async Task <ScheduleDto> GetNewScheduleAsync(ScheduleRequestDto scheduleRequest) { // Get team members from repository var teamMembers = await _employeeRepository.QueryNoTracking() .Where(w => w.IsActive) // Active ones for next schedule .OrderBy(c => new Random().Next()) // Shuffle staff order .Take(scheduleRequest.NumberOfEmployees) // we take a number from all employees in demo .ToListAsync(); // Get transition set rules from repository var transitionSet = await _transitionSetRepository.QueryNoTracking() .Where(w => w.Id == scheduleRequest.TransitionSetId && w.IsActive) // active transition set .FirstOrDefaultAsync(); // We only have that number of employees if (teamMembers.Count < scheduleRequest.NumberOfEmployees) { throw new ArgumentOutOfRangeException($"Invalid number of employees for scheduling."); } // Check we have the active transition set if (transitionSet == null) { throw new ArgumentOutOfRangeException($"Invalid transition set defined."); } var ruleSet = TransitionSet.FromRuleSetString(transitionSet.Name, transitionSet.RuleSetString).RuleSet; // Take 5 solutions as a demo result var schedules = await _teamShiftScheduler.CreateNewScheduleAsync(ruleSet, teamMembers, scheduleRequest.StartDate.Date, scheduleRequest.Days, scheduleRequest.TeamSize, scheduleRequest.MinShiftsPerCycle, scheduleRequest.StartHour, scheduleRequest.ShiftHours, 5); // Play with results for demo if (schedules.Count > 0) { return(ScheduleDto.FromEntity(schedules[new Random().Next(schedules.Count)], GetLatestStatistics())); } // Return default with statistics on model error return(new ScheduleDto() { Statistics = GetLatestStatistics(), Error = GetLatestError() }); // Or just return first. // return ScheduleToDto(schedules.FirstOrDefault()); }
public ActionResult RunSchedule(ScheduleDto scheduleDto) { ActionResult ActionResult = new ActionResult(); string Data = SchedulerFactory.Run_Schedule(scheduleDto); if (Data == "Success") { ActionResult.Message = Localization.GetString("RunNow", Components.Constants.TaskSchedulerResourcesFile); } else { ActionResult.AddError("RunNowError", Localization.GetString("RunNowError", Components.Constants.TaskSchedulerResourcesFile)); } return(ActionResult); }
static ScheduleRow mapToScheduleRow(ScheduleDto pSchedule) { if (pSchedule == null) { return(null); } ScheduleRow _scheduleRow = new ScheduleRow(); _scheduleRow.Schedule_id = pSchedule.ScheduleId; _scheduleRow.ScheduleType = pSchedule.ScheduleType; _scheduleRow.DayOfWeek = pSchedule.DayOfWeek; _scheduleRow.Day_of_the_month_1 = pSchedule.DayOfTheMonth1; _scheduleRow.Day_of_the_month_2 = pSchedule.DayOfTheMonth2; return(_scheduleRow); }
public ControllerResponse AddOrUpdateSchedule([FromBody] ScheduleDto scheduleToRender) { var doctorId = 0; if (User.Identity.IsAuthenticated) { doctorId = int.Parse(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value); } if (!scheduleToRender.ValidateScheduleToUpdating()) { return(ControllerResponse.Warning("Данные были не введены или введены не полностью, повторите запрос")); } _doctorServices.UpdateSchedule(new ScheduleWithDateTransfer(scheduleToRender, doctorId)); return(ControllerResponse.Ok()); }
public IHttpActionResult Put(ScheduleDto schedule) { ScheduleDto response; using (_scheduleService) { response = _scheduleService.Update(schedule); } if (response != null) { return(Ok(response)); } return(NotFound()); }
static ScheduleDto mapToSchedule(ScheduleRow pScheduleRow) { if (pScheduleRow == null) { return(null); } ScheduleDto _schedule = new ScheduleDto(); _schedule.ScheduleId = pScheduleRow.Schedule_id; _schedule.ScheduleType = pScheduleRow.ScheduleType; _schedule.DayOfWeek = pScheduleRow.DayOfWeek; _schedule.DayOfTheMonth1 = pScheduleRow.Day_of_the_month_1; _schedule.DayOfTheMonth2 = pScheduleRow.Day_of_the_month_2; return(_schedule); }
public HttpResponseMessage DeleteSchedule(ScheduleDto scheduleDto) { try { var objScheduleItem = new ScheduleItem { ScheduleID = scheduleDto.ScheduleID }; SchedulingProvider.Instance().DeleteSchedule(objScheduleItem); return(Request.CreateResponse(HttpStatusCode.OK, new { Success = true })); } catch (Exception exc) { Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public async Task <ActionResult> GetSchedules([FromBody] ScheduleDto schedule) { var response = new Response <ScheduleDto>(); try { response.Object = await _scheduleLogic.InsertSchedule(schedule); } catch (Exception e) { response.IsError = true; response.ErrorMessage = "Unexpected error"; _logger.LogError($"ScheduleController | Error | Error message : {e.Message}"); } return(Ok(response)); }
public ScheduleDto GetRepaymentSchedule(double amount, double apr, int period = 52) { var result = new ScheduleDto(); var loanSummary = GetLoanSummary(amount, apr, period); var amountDue = amount; var installmentAmount = loanSummary.WeeklyPayment; result.Installments = new List <InstallmentDto>(); for (int week = 1; week <= period; week++) { InstallmentDto installment = calculateBalanceAmount(installmentAmount, amountDue, apr, period, week); result.Installments.Add(installment); amountDue -= installment.Principal; } return(result); }
public async Task <ActionResult <bool> > AddSchedule(ScheduleDto scheduleDto) { String[] fromlist = scheduleDto.Fromtime.Split(":"); String[] tolist = scheduleDto.ToTime.Split(":"); var schedule = new Schedule { Fromtime = new TimeSpan(int.Parse(fromlist[0]), int.Parse(fromlist[1]), 0), ToTime = new TimeSpan(int.Parse(tolist[0]), int.Parse(tolist[1]), 0), Day = scheduleDto.Day, CourseId = scheduleDto.CourseId }; unitOfWork.ScheduleRepository.AddScheduleAsync(schedule); return(await unitOfWork.Complete()); }
public ScheduleDto SeedSchedule() { var teamDto = SeedTeam(); var userDto = SeedUser(); ScheduleDto dto = new ScheduleDto() { ScheduleId = Guid.NewGuid(), TeamId = teamDto.TeamId, UserId = userDto.UserId, StartDate = Convert.ToDateTime("5/1/2000"), EndDate = Convert.ToDateTime("5/5/2000") }; Schedule.SaveSchedule(dto); return(dto); }
public async Task <IActionResult> UpdateSchedule(ScheduleDto schedule) { Logger.Here().Info("{UpdateSchedule()} - {schedule}", nameof(UpdateSchedule), schedule); if (await ScheduleContainsReservations(schedule.Id)) { Logger.Here().Info("{UpdateSchedule()} - {schedule} - contains reservations", nameof(UpdateSchedule), schedule); return(BadRequestResponse("Schedule contains reservations!")); } if (await _service.CreateScheduleService().UpdateScheduleAsync(schedule)) { return(UpdatedResponse()); } Logger.Here().Info("{UpdateSchedule} - {schedule} - not deletable", nameof(UpdateSchedule), schedule); return(BadRequestResponse("Schedule is not updateable!")); }
public void Update(int id, ScheduleDto scheduleDto) { if (!_scheduleRepository.CheckIfExist(id)) { throw new ValidationException("Schedule not found!"); } Schedule schedule = _mapper.Map <Schedule>(scheduleDto); if (!_scheduleValidator.VerifySchedule(schedule)) { throw new ValidationException("Invalid schedule format", scheduleDto); } schedule.BusinessId = id; _scheduleRepository.Update(schedule); }
public IActionResult Update(int id, [FromBody] ScheduleDto scheduleDto) { if (Convert.ToInt32(User.Identity.Name) != id) { return(Unauthorized()); } try { _scheduleService.Update(id, scheduleDto); return(Ok()); } catch (ValidationException ex) { return(BadRequest(new { message = ex.Message })); } }
public ScheduleDto Update(ScheduleDto scheduleDto) { using (_scheduleRepository) { if (!_scheduleRepository.Exists(x => x.ScheduleId == scheduleDto.ScheduleId)) { return(null); } var entityToBeUpdated = scheduleDto.ConvertToScheduleDbModel(); _scheduleRepository.Update(entityToBeUpdated); _scheduleRepository.SaveChanges(); return(entityToBeUpdated.ConvertToScheduleDto()); } }
public static ScheduleView ToViewModel(this ScheduleDto scheduleDto) { if (scheduleDto == null) { return(null); } return(new ScheduleView { Id = scheduleDto.Id, Date = scheduleDto.Date.ToString("dd/MM/yyyy"), MovieId = scheduleDto.MovieId, SessionId = scheduleDto.SessionId, Movie = scheduleDto.Movie.ToViewModel(), Session = scheduleDto.Session.ToViewModel() }); }
internal static void Save(Rbr_Db pDb, ScheduleDto pSchedule) { ScheduleRow _scheduleRow = mapToScheduleRow(pSchedule); if (_scheduleRow != null) { if (_scheduleRow.Schedule_id == 0) { pDb.ScheduleCollection.Insert(_scheduleRow); pSchedule.ScheduleId = _scheduleRow.Schedule_id; } else { pDb.ScheduleCollection.Update(_scheduleRow); } } }
public HttpResponseMessage UpdateScheduleItem(ScheduleDto scheduleDto) { try { if (scheduleDto.RetryTimeLapse == 0) { scheduleDto.RetryTimeLapse = Null.NullInteger; } if (!VerifyValidTimeLapseRetry(scheduleDto.TimeLapse, scheduleDto.TimeLapseMeasurement, scheduleDto.RetryTimeLapse, scheduleDto.RetryTimeLapseMeasurement)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Localization.GetString("InvalidFrequencyAndRetry", localResourcesFile))); } var existingItem = SchedulingProvider.Instance().GetSchedule(scheduleDto.ScheduleID); var updatedItem = _controller.CreateScheduleItem(scheduleDto.TypeFullName, scheduleDto.FriendlyName, scheduleDto.TimeLapse, scheduleDto.TimeLapseMeasurement, scheduleDto.RetryTimeLapse, scheduleDto.RetryTimeLapseMeasurement, scheduleDto.RetainHistoryNum, scheduleDto.AttachToEvent, scheduleDto.CatchUpEnabled, scheduleDto.Enabled, scheduleDto.ObjectDependencies, scheduleDto.ScheduleStartDate, scheduleDto.Servers); updatedItem.ScheduleID = scheduleDto.ScheduleID; if (updatedItem.ScheduleStartDate != existingItem.ScheduleStartDate || updatedItem.Enabled || updatedItem.Enabled != existingItem.Enabled || updatedItem.TimeLapse != existingItem.TimeLapse || updatedItem.RetryTimeLapse != existingItem.RetryTimeLapse || updatedItem.RetryTimeLapseMeasurement != existingItem.RetryTimeLapseMeasurement || updatedItem.TimeLapseMeasurement != existingItem.TimeLapseMeasurement) { SchedulingProvider.Instance().UpdateSchedule(updatedItem); } else { SchedulingProvider.Instance().UpdateScheduleWithoutExecution(updatedItem); } return(Request.CreateResponse(HttpStatusCode.OK, new { Success = true })); } catch (Exception exc) { Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public async Task DeleteATemplate() { var tempSchedule = new ScheduleDto() { ScheduleDate = DateTimeOffset.Now.Date }; await _createScheduleCommand.ExecuteAsync(tempSchedule); var result = await _getScheduleQuery.ExecuteAsync(x => x.ScheduleDate == tempSchedule.ScheduleDate); var schedule = result.First(); tempSchedule = _mapper.Map <ScheduleDto>(schedule); await _sut.ExecuteAsync(tempSchedule); }
public async Task DeleteSchedule_InvalidRequests() { await Authenticate(); //Schedule contains references on reservations var schedule = new ScheduleDto { Id = 1L }; var response = await DeleteSchedule(schedule); await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.BadRequest); //Already deleted schedule schedule = DataSeeder.Schedules.Select(Map).Last(); response = await DeleteSchedule(schedule); await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.BadRequest); }
public static Schedule ToSqlModel(this ScheduleDto scheduleDto) { if (scheduleDto == null) { return(null); } return(new Schedule { Id = scheduleDto.Id, Date = scheduleDto.Date, MovieId = scheduleDto.MovieId, SessionId = scheduleDto.SessionId, Movie = scheduleDto.Movie.ToSqlModel(), Session = scheduleDto.Session.ToSqlModel(), IsDeleted = false }); }
public RoomDto ToRoomDto(Room room) { RoomPlanDto roomPlan = ToRoomPlanDto(roomRepository.GetRoomPlan(room.Id)); ScheduleDto schedule = ToScheduleDto(scheduleRepository.GetScheduleById(room.ScheduleId)); return(new RoomDto() { Id = room.Id, IsOpen = room.IsOpen, Name = room.Name, RoomPlan = roomPlan, RoomPlanId = roomPlan?.Id ?? -1, Schedule = schedule, ScheduleId = schedule?.Id ?? -1, Technology = mapper.Map <RoomTechnologyDto>(roomRepository.GetTechnologyById(room.TechnologyId)), TechnologyId = room.TechnologyId }); }
public async Task <ActionResult <string> > UpdateSchedule(ScheduleDto scheduleDto) { var courseFromDb = await unitOfWork.CourseRepository.GetCourseByIdAsync(scheduleDto.CourseId); if (scheduleDto.FacultyId == courseFromDb.UserId) { var schedule = mapper.Map <Schedule>(scheduleDto); unitOfWork.ScheduleRepository.UpdateSchedule(schedule); if (await unitOfWork.Complete()) { return(Ok("Schedule Updated Successfully")); } } return(BadRequest("Unauthorized Faculty ! Update Failed")); }
public void AddScheduleWithNoConflictsTest() { var teamDto = SeedTeam(); var userDto = SeedUser(); DateTime startDate = Convert.ToDateTime("1/1/2000"); DateTime endDate = startDate.AddDays(7).AddHours(1); ScheduleDto dto = new ScheduleDto() { ScheduleId = Guid.NewGuid(), TeamId = teamDto.TeamId, UserId = userDto.UserId, StartDate = startDate, EndDate = endDate }; var saveResult = Service.SaveSchedule(dto); Assert.IsTrue(saveResult.IsSuccess); var items = Service.GetSchedulesByTeamId(teamDto.TeamId, startDate.AddDays(1), endDate.AddDays(1)); foreach (var item in items) { if (item.ScheduleId == dto.ScheduleId) { Assert.AreEqual(dto.ScheduleId, item.ScheduleId); Assert.AreEqual(dto.TeamId, item.TeamId); Assert.AreEqual(dto.UserId, item.UserId); Assert.AreEqual(dto.StartDate, item.StartDate); Assert.AreEqual(dto.EndDate, item.EndDate); } } Assert.IsTrue(items.Count > 0); var deleteResult = Service.DeleteSchedule(dto.ScheduleId); Assert.IsTrue(deleteResult.IsSuccess); DeleteSeededTeam(teamDto.TeamId); DeleteSeededUser(userDto.UserId); }
public HttpResponseMessage PostSchedule(ScheduleDto scheduleDto) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } scheduleDto.UserId = User.Identity.Name; Schedule schedule = scheduleDto.ToEntity(); _scheduleRepository.Save(schedule); scheduleDto.ScheduleId = schedule.Id; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, scheduleDto); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = scheduleDto.ScheduleId })); return(response); }