Exemplo n.º 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> AddJob(int userId, JobForCreationDto jobForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var job = _mapper.Map <Job>(jobForCreationDto);

            job.Active = "Active";

            var partInfo = await _repo.GetPart(userId, jobForCreationDto.PartNumber);

            job.PartNumber = partInfo.PartNumber;
            job.userId     = userId;

            _repo.Add(job);

            if (await _repo.SaveAll())
            {
                var jobToReturn = _mapper.Map <JobForReturnDto>(job);
                return(CreatedAtRoute("GetJob", new { jobNum = job.JobNumber, userId = userId }, jobToReturn));
            }

            throw new Exception("Creation of job lot failed on save");
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddMachine(int userId, MachForCreationDto machForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var mach = _mapper.Map <Mach>(machForCreationDto);

            mach.userId = userId;

            _repo.Add(mach);

            if (await _repo.SaveAll())
            {
                var machToReturn = _mapper.Map <MachForCreationDto>(mach);
                return(CreatedAtRoute("GetMach", new { mach = mach.Machine, userId = userId }, machToReturn));
            }

            throw new Exception("Creation of machine failed on save");
        }
Exemplo n.º 4
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);

            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");
        }
        public async Task <IActionResult> AddPart(int userId, PartForCreationDto partForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var part = _mapper.Map <Part>(partForCreationDto);

            part.userId = userId;

            part.Active = "Active";

            _repo.Add(part);

            if (await _repo.SaveAll())
            {
                var partToReturn = _mapper.Map <PartForCreationDto>(part);
                return(CreatedAtRoute("GetPart", new { part = part.PartNumber, userId = userId }, partToReturn));
            }

            throw new Exception("Creation of part lot failed on save");
        }
        public async Task <IActionResult> AddOperation(int userId, OperationForCreationDto opForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var op = _mapper.Map <Operation>(opForCreationDto);

            var jobInfo = await _repo.GetJob(userId, opForCreationDto.JobNumber);

            op.JobNumber = jobInfo.JobNumber;
            op.userId    = userId;

            _repo.Add(op);

            if (await _repo.SaveAll())
            {
                var opToReturn = _mapper.Map <OperationForReturnDto>(op);
                return(CreatedAtRoute("GetOp", new { jobNum = op.JobNumber, opNum = op.OpNumber, userId = userId }, opToReturn));
            }

            throw new Exception("Creation of op lot failed on save");
        }