public void Create(CreateMasterTaskDto dto) { // //make sure this task name is unique // if (_context.MasterTasks.Any(x => x.Name == dto.Name)) { throw new System.Exception("Task name already exists."); } var mt = _mapper.Map <MasterTask>(dto); mt.IntFromHeight = Utility.SanitizeStringToInteger(dto.FromHeight); mt.IntToHeight = Utility.SanitizeStringToInteger(dto.ToHeight); var snooksValues = _helperService.CalculateSnooks(new SnooksCalculateDto { EffortType = mt.EffortType, FromHeight = mt.IntFromHeight, ToHeight = mt.IntToHeight, WeightLb = (int)dto.WeightLb }); mt.SnooksMale = snooksValues.StrMalePercentage; mt.SnooksFemale = snooksValues.StrFemalePercentage; var nioshIndex = _helperService.GetNioshIndex(new NioshCalculateDto { EffortType = dto.EffortType, FromHeight = mt.IntFromHeight, ToHeight = mt.IntToHeight, WeightLb = (int)dto.WeightLb }); mt.LiftingIndex = nioshIndex; foreach (var id in dto.IndustryIds) { //becuase we are creating multiple tasks //we have to clone this // var mtCloned = (MasterTask)mt.Clone(); var ind = _context.Industries.Find(id); ind.MasterTasks.Add(mtCloned); _context.SaveChanges(); foreach (int categoryId in dto.CategoryIds) { mtCloned.TaskCategoryMaps.Add(new TaskCategoryMap { TaskCategoryId = categoryId, MasterTaskId = mtCloned.Id }); } } _context.SaveChanges(); }
public bool Update(UpdateJobTaskDto dto) { var dbJobTask = _context.JobTasks.Find(dto.Id); // //make sure this task name is unique for this //jobTask // bool exists = (from item in _context.JobTasks where item.Id != dbJobTask.Id && item.Name == dto.Name && item.JobId == dbJobTask.JobId select item).Any(); if (exists) { throw new OccumetricException("This task name is already taken in this job description."); } // //calculate niosh and snooks // var snooksDto = new SnooksCalculateDto { EffortType = dto.EffortType, WeightLb = (int)dto.WeightLb, FromHeight = Utility.SanitizeStringToInteger(dto.FromHeight), ToHeight = Utility.SanitizeStringToInteger(dto.ToHeight), }; var snooksVm = _helperService.CalculateSnooks(snooksDto); dbJobTask.SnooksMale = snooksVm.StrMalePercentage; dbJobTask.SnooksFemale = snooksVm.StrFemalePercentage; var nioshDto = new NioshCalculateDto { WeightLb = (int)dto.WeightLb, EffortType = dto.EffortType, FromHeight = Utility.SanitizeStringToInteger(dto.FromHeight), ToHeight = Utility.SanitizeStringToInteger(dto.ToHeight), LiftDurationType = dto.LiftDurationType, LiftFrequencyType = dto.LiftFrequencyType }; dbJobTask.LiftingIndex = _helperService.GetNioshIndex(nioshDto); _mapper.Map <UpdateJobTaskDto, JobTask>(dto, dbJobTask); _context.SaveChanges(); return(true); }
public IActionResult CalculateNioshIndex(NioshCalculateDto dto) { return(Ok(_helperService.GetNioshIndex(dto))); }