Example #1
0
        public async Task <IActionResult> AddProduction(int userId, ProdForCreationDto prodForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var production = _mapper.Map <Production>(prodForCreationDto);

            var opInfo = await _repo.GetOp(userId, production.JobNumber, production.OpNumber);

            production.userId     = userId;
            production.InQuestion = false;
            production.Average    = true;

            _repo.Add(production);

            if (await _repo.SaveAll())
            {
                var prodToReturn = _mapper.Map <ProdForReturnDto>(production);
                return(CreatedAtRoute("GetProd", new { id = production.Id, userId = userId }, prodToReturn));
            }

            throw new Exception("Creation of production lot failed on save");
        }
        public async Task <IActionResult> UpdateOperation(int userId, string jobNum, string opNum, OperationForUpdateDto opForUpdateDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var opFromRepo = await _repo.GetOp(userId, jobNum, opNum);

            _mapper.Map(opForUpdateDto, opFromRepo);

            if (await _repo.SaveAll())
            {
                return(CreatedAtRoute("GetOp", new { jobNum = opFromRepo.JobNumber, opNum = opFromRepo.OpNumber, userId = userId }, opForUpdateDto));
            }

            throw new Exception($"Updating op operation {opNum} for {jobNum} failed on save");
        }
Example #3
0
        public async Task <IActionResult> AddHourly(int userId, HourlyForCreationDto hourlyForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var hourly = _mapper.Map <Hourly>(hourlyForCreationDto);

            var opInfo = await _repo.GetOp(userId, hourly.JobNumber, hourly.OpNumber);

            hourly.userId = userId;

            _repo.Add(hourly);

            if (await _repo.SaveAll())
            {
                var hourlyToReturn = _mapper.Map <HourlyForCreationDto>(hourly);
                return(CreatedAtRoute("GetHourly", new { id = hourly.Id, userId = userId }, hourlyToReturn));
            }

            throw new Exception("Creation of hourly count failed on save");
        }