コード例 #1
0
        private void AddStepOfferWykonanie(SaveCompleteStepViewModel model, int userId)
        {
            var itemToAdd = new StepOfferWykonanie()
            {
                LiczbaPomiarow    = model.LiczbaPomiarow,
                LiczbaPomiarowNok = model.LiczbaPomiarowNok,
                Zakonczonie       = model.Zakonczenie,
                ProcessId         = model.ProcessId,
                OfferLineId       = model.OfferLineId,
                Step         = model.StepNum,
                StartedOn    = DateTime.Now,
                ReasonCodeId = model.ReasonCodeId
            };

            if (model.Zakonczenie)
            {
                itemToAdd.ClosedOn = DateTime.Now;
                itemToAdd.ClosesBy = userId;
            }
            _dbContext.StepOfferWykonanie.Add(itemToAdd);
        }
コード例 #2
0
        public async Task <IActionResult> SaveStep([FromBody] SaveCompleteStepViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Bad model"));
            }
            try
            {
                var find = await _dbContext.StepOfferWykonanie.FirstOrDefaultAsync(p =>
                                                                                   p.OfferLineId == model.OfferLineId &&
                                                                                   p.Step == model.StepNum &&
                                                                                   p.ProcessId == model.ProcessId);

                if (find != null)
                {
                    find.LiczbaPomiarowNok = model.LiczbaPomiarowNok;
                    find.LiczbaPomiarow    = model.LiczbaPomiarow;
                    find.Zakonczonie       = model.Zakonczenie;
                    find.ReasonCodeId      = model.ReasonCodeId;
                    if (model.Zakonczenie)
                    {
                        if (CheckIsThisLastStep(model))
                        {
                            int countAllSteps = await _dbContext.Steps
                                                .Where(p =>
                                                       p.ProcessesId == model.ProcessId)
                                                .CountAsync();

                            int countFinishedSteps = await _dbContext.StepOfferWykonanie
                                                     .Where(p =>
                                                            p.ProcessId == model.ProcessId &&
                                                            p.OfferLineId == model.OfferLineId &&
                                                            p.Zakonczonie)
                                                     .CountAsync();

                            int countOfStepsNeededClosesBefore10 = countAllSteps - 1;

                            if (countFinishedSteps != countOfStepsNeededClosesBefore10)
                            {
                                throw new Exception("Trzeba zamknąć wszystkie inne kroki przez zamknięciem 10.");
                            }
                            //dodawanie na magazyb
                            var offerLine = await _dbContext.OfferLines.SingleAsync(p => p.Id == model.OfferLineId);

                            _dbContext.MagazynProdukty.Add(new MagazynProdukty()
                            {
                                DataPrzyjecia = DateTime.Now,
                                ElementId     = offerLine.ProductId,
                                Ilosc         = offerLine.Quantity,
                                KontrahentId  = 32, // 4yc
                            });
                        }
                        find.ClosedOn = DateTime.Now;
                        find.ClosesBy = this.GetUserId();
                    }
                }
                else
                {
                    AddStepOfferWykonanie(model, this.GetUserId());
                }
                var lstStepsStartedTimeRegisterToClose = await _dbContext.PracownikCzasStep.Where(p =>
                                                                                                  p.ProcessId == model.ProcessId &&
                                                                                                  p.OfferLinesId == model.OfferLineId &&
                                                                                                  p.CzasStart != null &&
                                                                                                  p.CzasStop == null).ToListAsync();

                foreach (var item in lstStepsStartedTimeRegisterToClose)
                {
                    item.CzasStop = DateTime.Now;
                }
                await _dbContext.SaveChangesAsync();

                //var res = await _ctx.Offer.Include(p => p.Clients).Include(p => p.OfferLines).ThenInclude(p => p.Product).ToListAsync();
                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
コード例 #3
0
 private static bool CheckIsThisLastStep(SaveCompleteStepViewModel model)
 {
     return(model.StepNum == 10);
 }