public async Task <IActionResult> Index(JobCardViewModel jobCardViewModel)
        {
            try
            {
                Random r = new Random();
                if (ModelState.IsValid)
                {
                    var job = new JobCards
                    {
                        CreatedDate      = DateTime.Now,
                        DateOfCompletion = jobCardViewModel.DateOfCompletion,
                        Designation      = jobCardViewModel.Designation,
                        Division         = jobCardViewModel.Division,
                        Email            = jobCardViewModel.Email,
                        Indentor         = jobCardViewModel.Indentor,
                        isAccept         = false,
                        isReject         = false,
                        isComplete       = false,
                        //JobId = "JOB" + r.Next(100000, 999999),
                        Name            = jobCardViewModel.Name,
                        NatureOfService = jobCardViewModel.NatureOfService,
                        PhoneNumber     = jobCardViewModel.PhoneNumber
                    };
                    _context.Add(job);
                    _context.SaveChanges();
                    var temp        = job.Id.ToString();
                    var jobId       = "JOB" + temp.PadLeft(6, '0');
                    var updateJobId = _context.JobCards.FirstOrDefault(x => x.Id == job.Id);
                    updateJobId.JobId = jobId;
                    _context.SaveChanges();


                    await SendMail(jobCardViewModel);


                    _logger.LogInformation("Add Job Card");
                    jobCardViewModel.Id          = job.Id;
                    jobCardViewModel.JobId       = job.JobId;
                    jobCardViewModel.CreatedDate = job.CreatedDate;
                }

                return(View(jobCardViewModel));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw ex;
            }
        }
Exemple #2
0
        //Add jobcards
        public void MaintenanceSecondCheckUp()
        {
            int?MaintenanceCheckupStep2 = db.Settings.FirstOrDefault(s => s.Name == "MaintenanceStep2Value").Value;

            List <MaintenanceType>    MaintenanceType    = db.MaintenanceType.ToList();
            List <MaintenanceHistory> MaintenanceHistory = db.MaintenanceHistory.Where(m => m.MaintenanceStatus == null).ToList();

            foreach (var item in MaintenanceHistory)
            {
                JobCards jobCards = db.JobCards.FirstOrDefault(j => j.IsOpen == true && j.CheckUpCard.InitialControlSchedule.VehicleId == item.InitialControlSchedule.VehicleId);

                if (jobCards == null)
                {
                    foreach (var item2 in MaintenanceType)
                    {
                        if (item.MaintenanceId == item2.Id && db.InitialControlSchedule.Where(i => i.IsOpen == false && i.VehicleId == item.InitialControlSchedule.VehicleId).OrderByDescending(k => k.EnterTime).FirstOrDefault().EnterKilometer > (item2.MaintenanceValue + MaintenanceCheckupStep2))
                        {
                            //Create Checkup card
                            CheckUpCard checkUpCard = new CheckUpCard();
                            checkUpCard.InitContId        = item.InitContId;
                            checkUpCard.MaintenanceTypeId = item2.Id;
                            checkUpCard.Description       = "Created by System. Texniki qulluq - " + item2.Name + "/" + item2.MaintenanceValue + "  / Faktiki kilometr " + db.InitialControlSchedule.Where(i => i.VehicleId == item.InitialControlSchedule.VehicleId).OrderByDescending(i => i.EnterTime).FirstOrDefault().EnterKilometer;
                            checkUpCard.IsOpen            = true;
                            checkUpCard.AddedDate         = DateTime.Now;


                            //Create Jobcard
                            int?     ConstantNo  = db.Settings.FirstOrDefault(s => s.Name == "JobCardNoStart").Value;
                            int?     MaxNo       = db.JobCards.Max(j => j.JobCardNo);
                            JobCards newJobCards = new JobCards();
                            if (MaxNo != null)
                            {
                                newJobCards.JobCardNo = MaxNo + 1;
                            }
                            else
                            {
                                newJobCards.JobCardNo = ConstantNo;
                            }
                            newJobCards.CheckupCardId   = checkUpCard.Id;
                            newJobCards.IsOpen          = true;
                            newJobCards.CreatedBySystem = true;
                            newJobCards.IsMaintenance   = true;
                            newJobCards.InUnderRepair   = true;
                            newJobCards.AddedDate       = DateTime.Now;
                            newJobCards.CompanyId       = db.Companies.FirstOrDefault(c => c.IsClient == true).Id;

                            ////Updating Maintenance history
                            //MaintenanceHistory maintenanceHistory = db.MaintenanceHistory.Find(item.Id);
                            //maintenanceHistory.JobCardId = newJobCards.Id;
                            //db.Entry(maintenanceHistory).State = EntityState.Modified;

                            //Adding to db and saving
                            db.CheckUpCard.Add(checkUpCard);
                            db.JobCards.Add(newJobCards);

                            //Check for maintenance history and create requisitioin
                            CheckForMaintenanceHistoryAndCreateRequisition(checkUpCard.InitialControlSchedule.VehicleId, checkUpCard, newJobCards);

                            db.SaveChanges();
                        }
                    }
                }
            }
        }
Exemple #3
0
        //End of background jobs

        //Check for maintenance history and create requisitioin
        public void CheckForMaintenanceHistoryAndCreateRequisition(int?VehicleId, CheckUpCard CheckUp, JobCards jobCard)
        {
            //Check for maintenance
            MaintenanceHistory maintenanceHistory = db.MaintenanceHistory.FirstOrDefault(m => m.MaintenanceStatus == null && m.JobCardId == null && m.InitialControlSchedule.VehicleId == VehicleId);

            if (maintenanceHistory != null)
            {
                CheckUp.MaintenanceTypeId = maintenanceHistory.MaintenanceId;
                jobCard.IsMaintenance     = true;

                //Updating Maintenance history
                MaintenanceHistory newMaintenanceHistory = db.MaintenanceHistory.Find(maintenanceHistory.Id);
                newMaintenanceHistory.JobCardId = jobCard.Id;
                if (ModelState.IsValid)
                {
                    db.Entry(newMaintenanceHistory).State = EntityState.Modified;
                }

                //Create Requisition
                int?brandId = db.Vehicles.Find(VehicleId).BrandId;
                List <WarehouseToMaintenance> warehouseToMaintenances = db.WarehouseToMaintenance.Where(w => w.MaintenanceTypeId == maintenanceHistory.MaintenanceId && w.TempWarehouse.VehicleId == brandId).ToList();

                foreach (var item in warehouseToMaintenances)
                {
                    //If it is includes to the range(if true) must not erquire SP else require
                    if (!CheckForSparePartIfMustAdd(VehicleId, item.NotRequireSPLimit, item.WarehouseId))
                    {
                        Requisitions requisition = new Requisitions();
                        requisition.IsOpen           = true;
                        requisition.JobCardId        = jobCard.Id;
                        requisition.TempWarehouseId  = item.WarehouseId;
                        requisition.RequiredQuantity = item.Quantity;
                        requisition.AddedDate        = DateTime.Now;

                        db.Requisitions.Add(requisition);
                        db.SaveChanges();
                    }
                }
            }
        }