public async Task <IActionResult> List()
        {
            var list = new GatePassModel();
            var allotedVehicesList = await _vehicleAllotmentService.GetAllAllotedVehiclesAsync();

            if (allotedVehicesList != null)
            {
                foreach (var item in allotedVehicesList)
                {
                    var vehicle = await _vehicleMasterService.GetByIdAsync((int)item.VehicleId);

                    var sc = await _userMasterService.GetUserByIdAsync((int)item.Scid);

                    var model = new AllotedVehicleDetailsModel();
                    model.AllotId         = item.Id;
                    model.Model           = vehicle.ModelVarient;
                    model.Colour          = vehicle.ModelColour;
                    model.VINNumber       = vehicle.Vinnumber;
                    model.EngineNumber    = vehicle.EngineNumber;
                    model.KeyNo           = vehicle.KeyNumber;
                    model.CustomerName    = (await _customerService.GetAllCustomerByIdAsync((int)item.CustomerId)).CustomerName;
                    model.SalesConsultant = sc.FirstName + " " + sc.LastName;
                    model.BranchName      = (await _branchMasterService.GetBranchByIdAsync((int)item.BranchId)).BranchName;
                    model.AllotDate       = Convert.ToDateTime(item.DateCreated).ToString("dd/MM/yyyy");
                    list.AllotedVehicleDetails.Add(model);
                }
            }
            list.AvaillablePlaces = BindVehicleOutTo();


            return(View(list));
        }
Beispiel #2
0
        public async Task <IActionResult> CustomerVehicleAllotment(IFormCollection form)
        {
            try
            {
                var custId   = Convert.ToInt32(form["CustId"]);
                var vehId    = Convert.ToInt32(form["item.VID"]);
                var custInfo = await _customerService.GetAllCustomerByIdAsync(custId);

                if (custInfo == null)
                {
                    //create cust entry
                    var customer = new CustomerDetailsTable
                    {
                        CustomerName = form["CustomerName"],
                        Address1     = form["Address1"],
                        Address2     = !string.IsNullOrEmpty(form["Address2"].ToString()) ? form["Address2"].ToString() : string.Empty,
                        EmailId      = form["EmailId"],
                        Pin          = form["Pin"],
                        Taluka       = form["Taluka"],
                        District     = form["District"],
                        State        = Convert.ToInt32(form["StateId"]),
                        MobileNo1    = Convert.ToDecimal(form["MobileNo1"]),
                        MobileNo2    = Convert.ToDecimal(form["MobileNo2"]),
                        DateUpdated  = DateTime.UtcNow,
                        DateCreated  = DateTime.UtcNow
                    };
                    await _customerService.InsertAsync(customer);

                    custId = customer.Id;
                }

                //add record in table
                if (vehId != 0)
                {
                    var vehicleAllotDetails = new VehicleAllotmentDetails
                    {
                        VehicleId   = Convert.ToInt32(form["item.VID"]),
                        CustomerId  = custId,
                        ModelId     = Convert.ToInt32(form["ModelId"]),
                        VarientId   = Convert.ToInt32(form["VarientId"]),
                        ColourId    = Convert.ToInt32(form["VarientColourId"]),
                        VarientType = form["VarientType"],
                        Scid        = Convert.ToInt32(form["SalesConsultantId"]),
                        BranchId    = Convert.ToInt32(form["BranchId"]),
                        DateCreated = DateTime.UtcNow,
                        DateUpdated = DateTime.UtcNow,
                        AllotedBy   = Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value),
                    };
                    await _vehicleAllotmentService.InsertAsync(vehicleAllotDetails);

                    //update vehicle status in vehicle master
                    var vehicle = await _vehicleMasterService.GetByIdAsync(vehId);

                    if (vehicle != null)
                    {
                        vehicle.TrackStatus = vehicleAllotDetails.IsAlloted ? VehicleStatusEnum.Alloted.ToString() : VehicleStatusEnum.PartiallyAlloted.ToString();
                        vehicle.DateUpdated = DateTime.UtcNow;
                        await _vehicleMasterService.UpdateAsync(vehicle);
                    }
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }