Exemple #1
0
        public async Task <IActionResult> Edit(VehicleAllotmentModel viewModel, bool continueEditing)
        {
            var existingAllotment = await _vehicleAllotmentService.GetByIdAsync(viewModel.Id);

            existingAllotment.IsAlloted   = viewModel.IsAlloted;
            existingAllotment.ApprovedBy  = Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value);
            existingAllotment.DateUpdated = DateTime.UtcNow;
            await _vehicleAllotmentService.UpdateAsync(existingAllotment);

            //update vehicle track status
            var existingVehicle = await _vehicleMasterService.GetByIdAsync((int)existingAllotment.VehicleId);

            if (existingVehicle != null)
            {
                existingVehicle.TrackStatus = VehicleStatusEnum.Alloted.ToString();
                existingVehicle.DateUpdated = DateTime.UtcNow;
                await _vehicleMasterService.UpdateAsync(existingVehicle);
            }
            AllowContinueEditing(continueEditing);
            //TempData["UserMessageSuccess"] = "Record saved sucessfully.";

            if (continueEditing)
            {
                return(RedirectToAction(nameof(Edit), new { id = existingAllotment.Id }));
            }

            return(RedirectToAction(nameof(List)));
        }
        public async Task <IActionResult> List(GatePassModel model, IFormCollection form)
        {
            try
            {
                string bName = "";
                int    bId   = 0;
                var    user  = await _userMasterService.GetUserByIdAsync(Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value));

                if (model.OutTo == VehicleOutToEnum.Showroom.ToString())
                {
                    foreach (var v in model.AllotedVehicleDetails.Where(x => x.IsSelected.Selected == true))
                    {
                        var vehicle = await _vehicleAllotmentService.GetByIdAsync(v.AllotId);

                        var showroomVeh = new ShowroomVehiclesDetails
                        {
                            VehicleId       = vehicle.VehicleId,
                            CustomerId      = vehicle.CustomerId,
                            ScId            = vehicle.Scid,
                            SubDealerId     = vehicle.SubDealer,
                            VehicleCameFrom = "Godown",
                            DateCreated     = DateTime.UtcNow,
                            BranchId        = (int)vehicle.BranchId,
                            ByUser          = user.Id
                        };
                        await _showroomVehiclesService.InsertAsync(showroomVeh);

                        bName = v.BranchName;
                        bId   = showroomVeh.BranchId;
                    }
                }
                else
                {
                    foreach (var v in model.AllotedVehicleDetails.Where(x => x.IsSelected.Selected == true))
                    {
                        var pVehicle = await _vehicleAllotmentService.GetByIdAsync(v.AllotId);

                        var pdiVeh = new PdiVehiclesDetails
                        {
                            VehicleId       = pVehicle.VehicleId,
                            CustomerId      = pVehicle.CustomerId,
                            ScId            = pVehicle.Scid,
                            SubDealerId     = pVehicle.SubDealer,
                            VehicleCameFrom = "Godown",
                            DateCreated     = DateTime.UtcNow,
                            BranchId        = (int)pVehicle.BranchId,
                            ByUser          = user.Id
                        };
                        await _pdiVehicesService.InsertAsync(pdiVeh);

                        bName = v.BranchName;
                        bId   = pdiVeh.BranchId;
                    }
                }

                //add entry in gate pass tale
                var gatePass = new GatePassDetails
                {
                    VehicleOutTo  = model.OutTo,
                    VehicleOutFor = bName,
                    BranchId      = bId,
                    ByHand        = model.ByHand,
                    Status        = "Successfull",
                    DateCreated   = DateTime.UtcNow,
                    ByUser        = user.Id
                };
                await _gatePassService.InsertAsync(gatePass);

                foreach (var v in model.AllotedVehicleDetails.Where(x => x.IsSelected.Selected == true))
                {
                    var pVehicle1 = await _vehicleAllotmentService.GetByIdAsync(v.AllotId);

                    var gatePassVehicles = new GatePassVehicles
                    {
                        GatePassId  = gatePass.Id,
                        VehicleId   = (int)pVehicle1.VehicleId,
                        CustomerId  = (int)pVehicle1.CustomerId,
                        SubDealerId = pVehicle1.SubDealer,
                        DateCreated = DateTime.UtcNow
                    };
                    await _gatePassService.InsertGatePassVehicleAsync(gatePassVehicles);

                    //update alloted vehicle status
                    pVehicle1.IsVehicleOutFromGodown = true;
                    pVehicle1.DateUpdated            = DateTime.UtcNow;
                    await _vehicleAllotmentService.UpdateAsync(pVehicle1);

                    // update vehicle track status in vehicle master table
                    var vehicleInfo = await _vehicleMasterService.GetByIdAsync((int)pVehicle1.VehicleId);

                    vehicleInfo.TrackStatus = model.OutTo;
                    vehicleInfo.DateUpdated = DateTime.UtcNow;
                    await _vehicleMasterService.UpdateAsync(vehicleInfo);
                }



                //generate gate pass
                model.GatePassDate  = DateTime.UtcNow.ToString("dd-MMM-yyyy");
                model.GatePassNo    = gatePass.Id.ToString();
                model.VehicleoutTo  = model.OutTo;
                model.VehicleoutFor = bName;
                model.AuthPerson    = user.FirstName + " " + user.LastName;
                var gatepass = await _viewToStringRendererService.RenderToStringAsync("GatePassMaster/GatePassTemplate", model);

                HtmlToPdf   converter = new HtmlToPdf();
                PdfDocument doc       = converter.ConvertHtmlString(gatepass.ToString());
                byte[]      pdf       = doc.Save();
                doc.Close();

                return(File(pdf, "application/pdf", "gatepass.pdf"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }