Beispiel #1
0
        public TaskListItemViewModel Create(TaskEditModel editModel)
        {
            TaskDefinition definition = _taskDefinitionDAO.Get(editModel.DefinitionId);

            TimeSpan allowedExposureTime = new TimeSpanFactory().CreateFromStrings(editModel.Hours, editModel.Minutes);

            Task task = new Task()
            {
                Title                  = editModel.Title,
                Role                   = _roleDAO.Get(editModel.RoleId),
                NoiseProtection        = _noiseProtectionDAO.Get(editModel.NoiseProtectionId),
                NoiseLevelGuideline    = Convert.ToDecimal(editModel.NoiseLevelGuideline.Trim(), new CultureInfo("en-US")),
                Frequency              = editModel.Frequency,
                AllowedExposureMinutes = Convert.ToInt32(allowedExposureTime.TotalMinutes),
                TaskDefinition         = definition,
                ButtonPressed          = editModel.ButtonPressed,
                CultureName            = editModel.SelectedCultureName,
            };

            definition.Tasks.Add(task);

            _taskDefinitionDAO.Store(definition);

            TaskListItemViewModel viewModel = CreateTaskListItemViewModel(task);

            return(viewModel);
        }
        public PartialViewResult AddTaskRotation(RotationViewModel viewModel)
        {
            var rotation = _rotationDAO.Get(viewModel.RotationId);

            var validationViewModel = ValidateInput(viewModel, rotation);

            if (validationViewModel.ValidationErrors.Count > 0)
            {
                Response.StatusCode = 500;
                return(PartialView("_ValidationErrorSummary", validationViewModel));
            }

            var selectedTaskOperator  = CreateSelectedTask(viewModel.OperatorNoiseLevelMeasured, rotation.OperatorTask);
            var selectedTaskAssistant = CreateSelectedTask(viewModel.AssistantNoiseLevelMeasured, rotation.AssistantTask);

            var noiseProtectionAssistant = _noiseProtectionDAO.Get(selectedTaskAssistant.NoiseProtectionId);
            var noiseProtectionOperator  = _noiseProtectionDAO.Get(selectedTaskOperator.NoiseProtectionId);

            var timeSpan = new TimeSpan(CreateTimeSpan(viewModel.Hours, viewModel.Minutes).Ticks / 2);

            var percentageOperator  = (int)Math.Round(rotation.OperatorTask.CalculatePercentage(selectedTaskOperator.Task.TaskDefinition.RoleType.ToString(), selectedTaskOperator.NoiseLevel, selectedTaskOperator.ButtonPressed, selectedTaskOperator.BackgroundNoise, selectedTaskOperator.Task.Frequency, noiseProtectionOperator, timeSpan));
            var percentageAssistant = (int)Math.Round(rotation.AssistantTask.CalculatePercentage(selectedTaskAssistant.Task.TaskDefinition.RoleType.ToString(), selectedTaskAssistant.NoiseLevel, selectedTaskAssistant.ButtonPressed, selectedTaskAssistant.BackgroundNoise, selectedTaskOperator.Task.Frequency, noiseProtectionAssistant, timeSpan));

            selectedTaskOperator.AddWorkTime(timeSpan, percentageOperator);
            selectedTaskAssistant.AddWorkTime(timeSpan, percentageAssistant);

            _selectedTaskDAO.Store(selectedTaskOperator);
            _selectedTaskDAO.Store(selectedTaskAssistant);

            var selectedTaskRotationViewModel =
                new SelectedTasksRotationViewModel
            {
                OperatorSelectedTaskViewModel  = new SelectedTaskViewModel(selectedTaskOperator),
                AssistantSelectedTaskViewModel = new SelectedTaskViewModel(selectedTaskAssistant)
            };

            return(PartialView("_SelectedTasksRotation", selectedTaskRotationViewModel));
        }
Beispiel #3
0
        public ActionResult AddTaskHelideck(HelideckViewModel viewModel)
        {
            var task = _taskDAO.Get(viewModel.TaskId);

            var validationViewModel = ValidateInput(viewModel);

            if (validationViewModel.ValidationErrors.Count > 0)
            {
                Response.StatusCode = 500;
                return(PartialView("_ValidationErrorSummary", validationViewModel));
            }

            var noiseProtection = _noiseProtectionDAO.Get(viewModel.NoiseProtectionId);
            var helicopterTask  = _helicopterTaskDAO.Get(viewModel.HelicopterId, task.Id);

            var selectedTask = new SelectedTask
            {
                NoiseLevel        = task.NoiseLevelGuideline,
                ButtonPressed     = task.ButtonPressed,
                NoiseProtectionId = viewModel.NoiseProtectionId,
                Title             = string.Format("{0} - {1}", task.Title, helicopterTask.HelicopterType.Title),
                Role             = task.Role.Title,
                NoiseProtection  = noiseProtection.Title,
                Percentage       = (int)CalculatePercentage(helicopterTask.NoiseLevel, task.ButtonPressed, 0, noiseProtection, new TimeSpan(0, 0, task.AllowedExposureMinutes, 0)),
                Minutes          = task.AllowedExposureMinutes,
                Task             = task,
                HelicopterTaskId = helicopterTask.Id,
                CreatedBy        = string.IsNullOrEmpty(User.Identity.Name) ? Session.SessionID : User.Identity.Name,
                CreatedDate      = DateTime.Now.Date,
                IsNoiseMeassured = false
            };

            _selectedTaskDAO.Store(selectedTask);

            return(PartialView("_SelectedTask", new SelectedTaskViewModel(selectedTask)));
        }
        public PartialViewResult EditTaskRegular(int id, RegularViewModel viewModel)
        {
            var selectedTask = _selectedTaskDAO.Get(id);

            var validationViewModel = ValidateInput(viewModel, selectedTask.Task);

            if (validationViewModel.ValidationErrors.Count > 0)
            {
                Response.StatusCode = 500;
                return(PartialView("_ValidationErrorSummary", validationViewModel));
            }

            selectedTask.ButtonPressed = viewModel.ButtonPressed;

            if (viewModel.BackgroundNoise != "<80")
            {
                int bNoise;
                if (int.TryParse(viewModel.BackgroundNoise, out bNoise))
                {
                    selectedTask.BackgroundNoise = bNoise;
                }
                else if (string.IsNullOrEmpty(viewModel.BackgroundNoise))
                {
                    selectedTask.BackgroundNoise = 0;
                }
            }

            if (viewModel.NoiseLevelMeassured == 0)
            {
                selectedTask.NoiseLevel       = selectedTask.Task.NoiseLevelGuideline;
                selectedTask.IsNoiseMeassured = false;
            }
            else if (viewModel.NoiseLevelMeassured != selectedTask.Task.NoiseLevelGuideline && viewModel.NoiseLevelMeassured != 0)
            {
                selectedTask.NoiseLevel       = viewModel.NoiseLevelMeassured;
                selectedTask.IsNoiseMeassured = true;
            }

            var noiseProtection = _noiseProtectionDAO.Get(viewModel.NoiseProtectionId);

            if (noiseProtection != null)
            {
                selectedTask.NoiseProtection   = noiseProtection.Title;
                selectedTask.NoiseProtectionId = noiseProtection.Id;
            }

            if (string.IsNullOrEmpty(viewModel.Hours) && string.IsNullOrEmpty(viewModel.Minutes))
            {
                selectedTask.Percentage = string.IsNullOrEmpty(viewModel.Percentage) ? 0 : int.Parse(viewModel.Percentage);
                var timeSpan = selectedTask.Task.CalculateTimeSpan(selectedTask.Task.TaskDefinition.RoleType.ToString(), selectedTask.NoiseLevel, selectedTask.ButtonPressed, selectedTask.BackgroundNoise, selectedTask.Task.Frequency, noiseProtection, selectedTask.Percentage);
                selectedTask.Hours         = timeSpan.Hours;
                selectedTask.Minutes       = timeSpan.Minutes;
                selectedTask.UsePercentage = true;
            }
            else
            {
                var timeSpan = new TimeSpanFactory().CreateFromStrings(viewModel.Hours, viewModel.Minutes);

                selectedTask.Hours         = timeSpan.Hours;
                selectedTask.Minutes       = timeSpan.Minutes;
                selectedTask.Percentage    = (int)Math.Round(selectedTask.Task.CalculatePercentage(selectedTask.Task.TaskDefinition.RoleType.ToString(), selectedTask.NoiseLevel, selectedTask.ButtonPressed, selectedTask.BackgroundNoise, selectedTask.Task.Frequency, noiseProtection, new TimeSpan(0, selectedTask.Hours, selectedTask.Minutes, 0)));
                selectedTask.UsePercentage = false;
            }

            _selectedTaskDAO.Store(selectedTask);

            return(PartialView("_SelectedTask", new SelectedTaskViewModel(selectedTask)));
        }