コード例 #1
0
        private void VacationClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
        {
            if ((bool)eventArgs.Parameter == false)
            {
                return;
            }
            eventArgs.Cancel();

            var dialogViewContent = (VacationDialogView)eventArgs.Content;
            var dialogData        = (VacationDialogViewModel)dialogViewContent.DataContext;

            VacationModel tempVacation = new VacationModel
            {
                From       = dialogData.DateFrom,
                To         = dialogData.DateTo,
                Type       = dialogData.SelectedVacationType,
                EmployeeId = dialogData.SelectedEmployee.Id
            };

            eventArgs.Session.UpdateContent(new ProgressDialog());

            using (_dbContext = new WHTDbContext())
            {
                _dbContext.Vacations.Add(tempVacation);
                _dbContext.SaveChanges();
            }
            NotifyOfPropertyChange(() => EmployeesVacations);

            Task.Delay(TimeSpan.FromSeconds(1))
            .ContinueWith((t, _) => eventArgs.Session.Close(false), null,
                          TaskScheduler.FromCurrentSynchronizationContext());
        }
コード例 #2
0
        private void ConfirmationClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
        {
            if ((bool)eventArgs.Parameter == false)
            {
                return;
            }

            eventArgs.Cancel();

            eventArgs.Session.UpdateContent(new ProgressDialog());

            using (_dbContext = new WHTDbContext())
            {
                var vacation = new VacationModel {
                    Id = SelectedEmployeeVacation.VacationId
                };
                _dbContext.Vacations.Attach(vacation);
                _dbContext.Vacations.Remove(vacation);
                _dbContext.SaveChanges();
            }
            NotifyOfPropertyChange(() => EmployeesVacations);

            Task.Delay(TimeSpan.FromSeconds(1))
            .ContinueWith((t, _) => eventArgs.Session.Close(false), null,
                          TaskScheduler.FromCurrentSynchronizationContext());
        }
コード例 #3
0
        private List <ScheduleSlots> GetExistedScheduledPropertySlots(long schedId)
        {
            var probRes = _appDbExtContext.ScheduleProperties.Where(x => x.ScheduleId == schedId).ToList();
            List <ScheduleSlots> existSlots = new List <ScheduleSlots>();

            foreach (var propItem in probRes)
            {
                var propResourceId = _appDbExtContext.Schedule.FirstOrDefault(x => x.Id == propItem.ScheduleId && x.RecordState == RecordState.N).ResourceId;

                switch ((SchedulePropertyTypeModel)propItem.ModelEnumId)
                {
                case SchedulePropertyTypeModel.Break:
                    var tmpBM = new BreakModel();
                    tmpBM.FromJson(propItem.Value);
                    tmpBM.ResourceId     = propResourceId;
                    tmpBM.ScheduleTimeId = propItem.ScheduleId;

                    existSlots.Add(tmpBM.ToSlot());
                    break;

                case SchedulePropertyTypeModel.Vocation:
                    var tmpVM = new VacationModel();
                    tmpVM.FromJson(propItem.Value);
                    tmpVM.ScheduleTimeId = propItem.ScheduleId;
                    tmpVM.ResourceId     = propResourceId;
                    existSlots.Add(tmpVM.ToSlot());
                    break;

                default: break;
                }
            }
            return(existSlots);
        }
コード例 #4
0
        private void CheckWorkingPeriod(VacationModel vacation, List <Vacation> employeeVacations, ServiceResult <VacationModel> result)
        {
            var lastVacation = employeeVacations.Where(x => x.End < vacation.Start).OrderBy(x => x.Start).LastOrDefault();

            if (lastVacation != null)
            {
                var minimumWorkPeriod = lastVacation.GetLength();

                if ((vacation.Start - lastVacation.End).Days <= minimumWorkPeriod)
                {
                    result.Messages.Add(
                        $"You can start new vacation only after {minimumWorkPeriod} days after end your last vacation");
                }
            }

            var nextVacation = employeeVacations.Where(x => x.Start > vacation.End).OrderBy(x => x.Start).FirstOrDefault();

            if (nextVacation != null)
            {
                var minimumWorkPeriod = vacation.GetLength();

                if ((nextVacation.Start - vacation.End).Days <= minimumWorkPeriod)
                {
                    result.Messages.Add(
                        $"You can end new vacation only before {minimumWorkPeriod} days before end your last vacation");
                }
            }
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            var longPressGesture = new UILongPressGestureRecognizer(gestureRecognizer =>
            {
                if (gestureRecognizer.State == UIGestureRecognizerState.Began)
                {
                    Editing = !Editing;
                }
            });

            View.AddGestureRecognizer(longPressGesture);


            Title = Localization.VacationsPageTitle;

            var barItem = new UIBarButtonItem(UIImage.FromBundle("add"),
                                              UIBarButtonItemStyle.Plain,
                                              async(sender, args) =>
            {
                var vac = new VacationModel();
                vac.Id  = await Context.App.Factory.Resolve <IVacationProvider>().AddAsync(vac);
                _itemsSource.Add(vac);
                ((UITableView)View).ReloadData();
            }
                                              );

            NavigationItem.SetLeftBarButtonItem(barItem, true);
            TableView.RegisterClassForCellReuse(typeof(VacationInfoCell), ReuseId);
        }
コード例 #6
0
 private void CheckEndLaterThenStart(VacationModel vacation, ServiceResult <VacationModel> result)
 {
     if (vacation.Start > vacation.End)
     {
         result.Messages.Add("Start can't be later then End");
     }
 }
コード例 #7
0
 private void CheckMinimumLength(VacationModel vacation, ServiceResult <VacationModel> result)
 {
     if (vacation.GetLength() > 0 && vacation.GetLength() < MinimumVacationLength)
     {
         result.Messages.Add($"Minimum length is {MinimumVacationLength} days");
     }
 }
コード例 #8
0
        private void CheckYearLimit(VacationModel vacation, List <Vacation> employeeVacations,
                                    ServiceResult <VacationModel> result)
        {
            var validationMessage            = $"Vacation limit exceeded. Year limit for vacation length is {YearVacationLimit} days";
            var employeeVacationsWithPlanned = employeeVacations.ToList();

            employeeVacationsWithPlanned.Add(_mapper.Map <Vacation>(vacation));
            var yearVacationSum = employeeVacationsWithPlanned
                                  .Where(x => x.Start.Year == vacation.Start.Year || x.End.Year == vacation.Start.Year)
                                  .Sum(x => x.GetDaysForYear(vacation.Start.Year));

            if (vacation.Start.Year == vacation.End.Year)
            {
                if (yearVacationSum > YearVacationLimit)
                {
                    result.Messages.Add(validationMessage);
                }
            }
            else
            {
                var startYearVacationSum = yearVacationSum;
                var endYearVacationSum   = employeeVacationsWithPlanned
                                           .Where(x => x.Start.Year == vacation.Start.Year || x.End.Year == vacation.Start.Year)
                                           .Sum(x => x.GetDaysForYear(vacation.Start.Year));
                if (startYearVacationSum > YearVacationLimit || endYearVacationSum > YearVacationLimit)
                {
                    result.Messages.Add(validationMessage);
                }
            }
        }
コード例 #9
0
 private void CheckMaximumLength(VacationModel vacation, ServiceResult <VacationModel> result)
 {
     if (vacation.GetLength() > MaximumVacationLength)
     {
         result.Messages.Add($"Vacation can't be longer than {MaximumVacationLength} days");
     }
 }
コード例 #10
0
        public int PostVacation(VacationModel vacModel)
        {
            List <Vacation> vacations = _db.Vacations.ToList();

            List <int> ids = new List <int>();

            foreach (Vacation v in vacations)
            {
                ids.Add(v.Id);
            }

            int max = 0;

            if (ids.Count() > 0)
            {
                max = ids.Max();
            }

            vacModel.Id = max + 1;
            Vacation vac = _vacToEntityAdapter.MapData(vacModel);

            _db.Vacations.Add(vac);
            try
            {
                _db.SaveChanges();
            }
            catch (Exception e)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }

            return(vacModel.Id);
        }
コード例 #11
0
 private void CheckIfIsFuture(VacationModel vacation, ServiceResult <VacationModel> result)
 {
     if (vacation.Start < DateTime.Today)
     {
         result.Messages.Add("You can't add vacations for past dates");
     }
 }
コード例 #12
0
        public ActionResult Put(string id, [FromBody] VacationRequestDto value)
        {
            var vacationModel = new VacationModel
            {
                Comment = value.Comment,
                From    = value.From,
                To      = value.To,
                Id      = Guid.Parse(id)
            };

            if (!string.IsNullOrWhiteSpace(value.Type))
            {
                vacationModel.Type = Enum.Parse <VacationType>(value.Type, true);
            }

            if (!string.IsNullOrWhiteSpace(value.State))
            {
                vacationModel.State = Enum.Parse <VacationState>(value.State, true);
            }

            var success = _service.UpdateVacation(vacationModel);

            Console.WriteLine($" update success? { success }");
            return(Ok());
        }
コード例 #13
0
        public ServiceResult <VacationModel> Edit(VacationModel newVacationModel)
        {
            var validationResult = _vacationProcessor.CanVacationBeCreated(newVacationModel);

            if (!validationResult.BadRequest)
            {
                return(validationResult);
            }

            var vacation = _unitOfWork.VacationRepository.Get(newVacationModel.Id);

            if (vacation == null)
            {
                return(new ServiceResult <VacationModel>()
                {
                    NotFound = true
                });
            }

            if (!vacation.IsInFuture())
            {
                return(new ServiceResult <VacationModel>("You can't edit past or ongoing vacations"));
            }

            vacation.Start = newVacationModel.Start;
            vacation.End   = newVacationModel.End;
            _unitOfWork.VacationRepository.Update(vacation);
            _unitOfWork.Save();
            return(new ServiceResult <VacationModel>(_mapper.Map <VacationModel>(vacation)));
        }
コード例 #14
0
        public Vacation MapData(VacationModel v)
        {
            Vacation mappedVacation = new Vacation();

            if (v != null)
            {
                if (v.Cover != null)
                {
                    mappedVacation.Cover = pictureAdapter.MapData(v.Cover);
                }
                mappedVacation.PromoText          = v.PromoText;
                mappedVacation.ContactInformation = contactInformationAdapter.MapData(v.ContactInformation, v.Id);
                mappedVacation.Included           = itemAdapter.MapData(v.Included);
                mappedVacation.Cost = priceAdapter.MapData(v.Cost, v.Id);
                mappedVacation.NumberOfParticipants = v.NumberOfParticipants;
                mappedVacation.When        = periodAdapter.MapData(v.When, v.Id);
                mappedVacation.Location    = locationAdapter.MapData(v.Location);
                mappedVacation.Comment     = commentAdapter.MapData(v.Comment, v.Id);
                mappedVacation.AgeRange    = arAdapter.MapData(v.Leeftijd, v.Id);
                mappedVacation.Titel       = v.Titel;
                mappedVacation.Id          = v.Id;
                mappedVacation.Tax_Benefit = v.Tax_Benefit;
            }

            return(mappedVacation);
        }
コード例 #15
0
        public ServiceResult <VacationModel> CanVacationBeCreated(VacationModel vacation)
        {
            var result = new ServiceResult <VacationModel>()
            {
                BadRequest = false
            };

            CheckEndLaterThenStart(vacation, result);
            CheckIfIsFuture(vacation, result);
            CheckConflictWithExistingVacation(vacation, result);
            CheckMinimumLength(vacation, result);
            CheckMaximumLength(vacation, result);
            var employeeVacations = _unitOfWork.VacationRepository.Where(x => x.EmployeeId == vacation.EmployeeId).ToList();

            CheckYearLimit(vacation, employeeVacations, result);
            CheckWorkingPeriod(vacation, employeeVacations, result);
            CheckPositionsOnVacation(vacation, result);

            if (result.Messages.Any())
            {
                result.BadRequest = true;
            }

            return(result);
        }
コード例 #16
0
        public async Task <VacationModel> CreateOrUpdateVacationAsync(VacationModel model, CancellationToken cancellationToken)
        {
            var dto         = model.ToVacationDTO();
            var vacationDto = await _vacationApi.CreateOrUpdateVacationAsync(dto, cancellationToken);

            return(vacationDto.ToVacationModel());
        }
コード例 #17
0
        public VacationModel MapData(Aug2015Backend.Entities.Vacation v)
        {
            VacationModel mappedVacation = new VacationModel();


            if (v != null)
            {
                mappedVacation.Pictures           = pictureAdapter.MapData(v.Picture);
                mappedVacation.Cover              = pictureAdapter.MapData(v.Cover);
                mappedVacation.PromoText          = v.PromoText;
                mappedVacation.ContactInformation = contactInformationAdapter.MapData(v.ContactInformation);
                mappedVacation.Included           = itemAdapter.MapData(v.Included);
                mappedVacation.Cost = priceAdapter.MapData(v.Cost);
                mappedVacation.NumberOfParticipants = v.NumberOfParticipants;
                mappedVacation.Location             = locationAdapter.MapData(v.Location);
                mappedVacation.When = periodAdapter.MapData(v.When);
                ICollection <CommentModel> comments = commentAdapter.MapData(v.Comment);
                mappedVacation.Comment     = comments;
                mappedVacation.Leeftijd    = arAdapter.MapData(v.AgeRange);
                mappedVacation.Titel       = v.Titel;
                mappedVacation.Id          = v.Id;
                mappedVacation.Tax_Benefit = v.Tax_Benefit;
            }

            return(mappedVacation);
        }
 public void UpdateData(VacationModel vacationModel)
 {
     _startDate.Text        = vacationModel.StartDate.ToString("dd/MM/yyyy");
     _endDate.Text          = vacationModel.EndDate.ToString("dd/MM/yyyy");
     _approverFullName.Text = vacationModel.ApproverId.ToString();
     _status.Text           = vacationModel.Status.ToString();
     _type.Text             = vacationModel.Type.ToString();
 }
コード例 #19
0
        public static VacationModel Vacation2VacationModel(Vacation vacation)
        {
            var vacationmodel = new VacationModel();

            vacationmodel.end    = vacation.end;
            vacationmodel.start  = vacation.start;
            vacationmodel.tripID = vacation.tripID;
            return(vacationmodel);
        }
コード例 #20
0
        public static Vacation VacationModel2Vacation(VacationModel vacationmodel)
        {
            var vacation = new Vacation();

            vacation.start  = vacationmodel.start;
            vacation.end    = vacationmodel.end;
            vacation.tripID = vacationmodel.tripID;
            return(vacation);
        }
コード例 #21
0
        public async Task <bool> VacationRequest([FromBody] VacationModel vocation)
        {
            var result = await _userContract.VacationRequest(_mapper.Map <VacationModel, VacationPOCO>(vocation));

            if (result)
            {
                return(true);
            }
            return(false);
        }
コード例 #22
0
        public VacationModel GetVacationModel(int formId)
        {
            var model = new VacationModel
            {
                Title   = "Sommerferie 2020",
                Comment = "Må ta ut 8 uker ferie, selv om jeg kun har 4 tilgjengelig. 4 uker i forskudd!"
            };

            return(model);
        }
コード例 #23
0
        private void CheckConflictWithExistingVacation(VacationModel vacation, ServiceResult <VacationModel> result)
        {
            var employeeVacations = _unitOfWork.VacationRepository.Where(x => x.EmployeeId == vacation.EmployeeId &&
                                                                         (vacation.Start <= x.Start && x.Start <= vacation.End ||
                                                                          vacation.Start <= x.End && x.End <= vacation.End));

            if (employeeVacations.Any())
            {
                result.Messages.Add("employee already has a vacation in this period");
            }
        }
コード例 #24
0
        public bool UpdateVacation(VacationModel vacation)
        {
            var tenant         = _tenantRepository.TenantId;
            var vacationModels = _vacationDatabase.GetOrAdd(tenant, new Dictionary <Guid, VacationModel>());

            if (!vacationModels.ContainsKey(vacation.Id))
            {
                throw new Exception($"key {vacation.Id} does not exist");
            }
            vacationModels[vacation.Id] = vacation;
            return(true);
        }
コード例 #25
0
        public Guid AddVacation(VacationModel vacation)
        {
            var id             = Guid.NewGuid();
            var tenant         = _tenantRepository.TenantId;
            var vacationModels = _vacationDatabase.GetOrAdd(tenant, new Dictionary <Guid, VacationModel>());

            vacation.Id = id;
            if (vacationModels.ContainsKey(id))
            {
                throw new Exception($"key {id} already exists");
            }
            vacationModels[id] = vacation;
            return(id);
        }
コード例 #26
0
        public DynamoDbVacationRepository(ITenantRepository tenantRepository)
        {
            _tenantRepository = tenantRepository;
            var defaultValues = _vacationDatabase.GetOrAdd("0", new Dictionary <Guid, VacationModel>());
            var value1        = new VacationModel
            {
                Id      = Guid.NewGuid(),
                Comment = "Some vacation makes me happy",
                From    = DateTime.UtcNow,
                To      = DateTime.UtcNow.AddDays(14)
            };

            defaultValues.Add(value1.Id, value1);
        }
コード例 #27
0
        public void EditVacation_VacationInPast_ErrorMessage()
        {
            var newVacationModel = new VacationModel()
            {
                Id         = _pastVacationId,
                Start      = DateTime.Today.AddDays(8),
                End        = DateTime.Today.AddDays(11),
                EmployeeId = _employeeId2
            };
            var result = _service.Edit(newVacationModel);

            Assert.IsTrue(result.BadRequest);
            Assert.IsTrue(result.GetMessage().ToLower().Contains("You can't edit past or ongoing vacations".ToLower()));
        }
コード例 #28
0
        public void EditVacation_VacationInFuture_VacationEdited()
        {
            var newVacationModel = new VacationModel()
            {
                Id         = _futureVacationId,
                Start      = DateTime.Today.AddDays(8),
                End        = DateTime.Today.AddDays(11),
                EmployeeId = _employeeId2
            };
            var result = _service.Edit(newVacationModel);

            Assert.IsFalse(result.BadRequest);
            Assert.AreEqual(_futureVacationId, result.Result.Id);
        }
コード例 #29
0
        public void CreateVacation()
        {
            var model = new VacationModel
            {
                Id             = Guid.NewGuid().ToString(),
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now.AddDays(1),
                Created        = DateTime.Now,
                CreatedBy      = "SomeOne",
                VacationType   = 1,
                VacationStatus = 2
            };

            _navigationService.NavigateToDetailsScreen(this, new VacationParameters(JsonConvert.SerializeObject(model)));
        }
コード例 #30
0
        private void CheckPositionsOnVacation(VacationModel vacation, ServiceResult <VacationModel> result)
        {
            var employee = _unitOfWork.EmployeeRepository.Get(vacation.EmployeeId);
            var otherEmployeesInPosition = _unitOfWork.EmployeeRepository
                                           .Where(x => x.PositionId == employee.PositionId && x.Id != vacation.EmployeeId).ToList();
            var otherEmployeesOnVacation = otherEmployeesInPosition
                                           .Count(x => x.Vacations.Any(y => (vacation.Start <= y.Start && y.Start <= vacation.End) ||
                                                                       (vacation.Start <= y.End && y.End <= vacation.End)));


            if ((int)((otherEmployeesInPosition.Count() + 1) * SamePositionEmployeeVacationThreshold) < otherEmployeesOnVacation + 1)
            {
                result.Messages.Add($"Not more than {SamePositionEmployeeVacationThreshold * 100}% employees with same position can get vacation on this period");
            }
        }