Exemplo n.º 1
0
        public ActionResult CurrentCarServiceEndJob(CurrentCarServiceDetailModel model)
        {
            // Get Car Information
            var CarServiceDetail = db.Garage_CarDaySetting.Where(q => q.Id == model.CurrentCarServiceId &&
                                                                 q.EntityTypeKey == (int)EntityTypeKey.Car
                                                                 ).SingleOrDefault();

            if (CarServiceDetail == null)
            {
                return(RedirectToAction("Index"));
            }
            CarServiceDetail.ServiceStatusId = (int)ServiceStatus.Complated;
            CarServiceDetail.EndTime         = DateTime.Now;
            db.SaveChanges();
            string ServiceName = string.Empty;
            int    carId       = Convert.ToInt32(CarServiceDetail.EntityTypeValue);



            var aspCar = db.CarUsers.Where(c => c.CarId == carId).SingleOrDefault();

            if (aspCar != null)
            {
                // Set Last and Next service date userPackage
                var activeUserPackage = aspCar.UserPackages.Where(u => u.PaymentRecieved == true && u.IsActive == true).FirstOrDefault();
                if (activeUserPackage != null)
                {
                    activeUserPackage.LastServiceDate = activeUserPackage.NextServiceDate;
                    activeUserPackage.NextServiceDate = Convert.ToDateTime(activeUserPackage.NextServiceDate).AddDays(activeUserPackage.SubscriptionTypeId * 7);
                }

                model.CarService = new CarServices()
                {
                    ServiceDayId   = CarServiceDetail.Id,
                    CarId          = aspCar.CarId,
                    CarDisplayName = aspCar.DisplayName,
                    Color          = aspCar.Color,
                    LicenseNumber  = aspCar.LicenseNumber,
                    serviceStatus  = (ServiceStatus)CarServiceDetail.ServiceStatusId,
                };


                // Get Car Services Information
                model.CarService.SelectServices = new List <CarServices.SelectService>();
                var pCarId = new SqlParameter();
                pCarId.ParameterName = "CarId";
                pCarId.Value         = aspCar.CarId;
                pCarId.DbType        = DbType.Int32;

                var servicesList = db.Database.SqlQuery <GreenPro.Data.Service>(
                    "EXEC dbo.GetServicesByCarId @CarId",
                    pCarId
                    ).ToList();



                if (servicesList.Count > 0)
                {
                    ServiceName += "<ul>";
                    foreach (var service in servicesList)
                    {
                        CarServices.SelectService seviceModel = new CarServices.SelectService();
                        seviceModel.ServiceName = service.Service_Name;
                        model.CarService.SelectServices.Add(seviceModel);
                        ServiceName += "<li>" + service.Service_Name + "</li>";
                    }

                    ServiceName += "</ul>";
                }
            }

            var userInfo = aspCar.AspNetUser;

            _workflowMessageService.SendCarServiceCompletionNotificationtoCustomer(userInfo.UserName, userInfo.Email, ServiceName);
            return(RedirectToAction("CurrentCarServiceDetail", "CrewLeader", new { id = model.CurrentCarServiceId }));
        }
        protected void PrepareDefaultSettingModel(DefaultSettingViewModel model, Garage garage, IQueryable <Garage_LeaderSetting> garageDefaultSettingEitity,
                                                  IList <Garage_CarDaySetting> garageCarDaySettingEntity, bool loadDefaultValue = true)
        {
            model.GarageId         = garage.GarageId;
            model.GarageName       = garage.Garage_Name;
            model.PrepareModelData = true;
            // Teams
            var TeamList = db.GarageTeams.Where(t => t.GarageId == model.GarageId).ToList();

            if (TeamList.Count <= 0)
            {
                model.PrepareModelData = false;
                ErrorNotification("Team not available.");
            }
            foreach (var team in TeamList)
            {
                model.AvailableTeams.Add(new SelectListItem()
                {
                    Text  = team.Title,
                    Value = team.Id.ToString()
                });
            }

            //// Crew Leader
            var LeadersList = (from u in db.AspNetUsers
                               join w in db.WorkerGarages
                               on u.Id equals w.CrewLeaderId
                               where w.IsLeader == true && u.AspNetRoles.Any(r => r.Name == "Crew Leader") &&
                               w.GarageID == model.GarageId
                               select u).ToList();

            if (LeadersList.Count <= 0)
            {
                model.PrepareModelData = false;
                ErrorNotification("Crew Leader not available.");
            }

            foreach (var leader in LeadersList)
            {
                model.AvailableLeaders.Add(new SelectListItem()
                {
                    Text  = leader.FirstName + " " + leader.LastName + "<br>" + leader.Email,
                    Value = leader.Id
                });
            }

            // Crew Member

            // var memberList = db.AspNetUsers.Where(u => u.AspNetRoles.Any(r => r.Name == "Crew Member")).ToList();
            var memberList = (from u in db.AspNetUsers
                              join w in db.WorkerGarages
                              on u.Id equals w.CrewLeaderId
                              where w.IsLeader == false && u.AspNetRoles.Any(r => r.Name == "Crew Member") &&
                              w.GarageID == model.GarageId
                              select u).ToList();

            if (memberList.Count <= 0)
            {
                model.PrepareModelData = false;
                ErrorNotification("Crew Member not available.");
            }

            foreach (var member in memberList)
            {
                model.AvailableMembers.Add(new SelectListItem()
                {
                    Text  = member.FirstName + " " + member.LastName + "<br>" + member.Email,
                    Value = member.Id
                });
            }

            // Garage Cars


            var garageList = db.Garages.Where(a => a.ServiceDays == model.ServiceDay).ToList();
            var carList    = (
                from c in db.CarUsers
                join
                up in db.UserPackages
                on c.CarId equals up.CarId
                join p in db.Packages
                on up.PackageId equals p.PackageId
                where c.GarageId == model.GarageId && up.PaymentRecieved == true && up.IsActive == true && up.ServiceDay == model.ServiceDay &&
                up.NextServiceDate == model.ServiceDate
                select new { CarId = c.CarId, DisplayName = c.DisplayName, LicenseNumber = c.LicenseNumber, c.Make, c.Color }).ToList();

            if (carList.Count <= 0)
            {
                model.PrepareModelData = false;
                ErrorNotification("Cars not available.");
            }


            string Description = string.Empty;

            foreach (var car in carList)
            {
                Description = string.Empty;

                Description = car.DisplayName;

                if (!string.IsNullOrEmpty(Description))
                {
                    Description += "<br>" + car.LicenseNumber;
                }

                if (!string.IsNullOrEmpty(Description))
                {
                    Description += "<br>" + car.Make;
                }

                if (!string.IsNullOrEmpty(Description))
                {
                    Description += "<br>" + car.Color;
                }

                model.AvailableCars.Add(new SelectListItem()
                {
                    Text  = Description,
                    Value = car.CarId.ToString()
                });
            }


            if (garageCarDaySettingEntity.Count > 0)
            {
                var garageDefaultSettingByDay = garageCarDaySettingEntity.Where(q => q.ServiceDay == model.ServiceDay).ToList();

                if (garageDefaultSettingByDay.Count > 0)
                {
                    // load existing leaders
                    foreach (var leader in LeadersList)
                    {
                        foreach (var team in TeamList)
                        {
                            bool selected = garageDefaultSettingByDay.Find(f => f.EntityTypeKey == (int)EntityTypeKey.Leader && f.EntityTypeValue == leader.Id && f.GarageTeamId == team.Id) != null;
                            if (!model.SelectedLeaders.ContainsKey(leader.Id))
                            {
                                model.SelectedLeaders[leader.Id] = new Dictionary <int, bool>();
                            }
                            model.SelectedLeaders[leader.Id][team.Id] = selected;
                        }
                    }

                    // load existing member
                    foreach (var leader in memberList)
                    {
                        foreach (var team in TeamList)
                        {
                            bool selected = garageDefaultSettingByDay.Find(f => f.EntityTypeKey == (int)EntityTypeKey.Member && f.EntityTypeValue == leader.Id && f.GarageTeamId == team.Id) != null;
                            if (!model.SelectedMembers.ContainsKey(leader.Id))
                            {
                                model.SelectedMembers[leader.Id] = new Dictionary <int, bool>();
                            }
                            model.SelectedMembers[leader.Id][team.Id] = selected;
                        }
                    }


                    // load existing cars
                    foreach (var car in carList)
                    {
                        foreach (var team in TeamList)
                        {
                            bool selected = garageDefaultSettingByDay.Find(f => f.EntityTypeKey == (int)EntityTypeKey.Car && f.EntityTypeValue == car.CarId.ToString() && f.GarageTeamId == team.Id) != null;
                            if (!model.SelectedCars.ContainsKey(car.CarId))
                            {
                                model.SelectedCars[car.CarId] = new Dictionary <int, bool>();
                            }
                            model.SelectedCars[car.CarId][team.Id] = selected;

                            if (selected)
                            {
                                var garageDefaultSettingByDayCarPaid = garageDefaultSettingByDay.Where(f => f.EntityTypeKey == (int)EntityTypeKey.Car && f.EntityTypeValue == car.CarId.ToString() && f.GarageTeamId == team.Id).SingleOrDefault();

                                var userpackageDetail = db.UserPackages.Where(u => u.CarId == car.CarId && u.IsActive == true).SingleOrDefault();
                                if (userpackageDetail != null)
                                {
                                    string PaymentStatus           = string.Empty;
                                    var    paypalAutoPaymentDetail = db.PaypalAutoPayments.Where(p => p.UserPackageID == userpackageDetail.Id && p.ServiceDate == model.ServiceDate).SingleOrDefault();

                                    if (paypalAutoPaymentDetail == null)
                                    {
                                        PaymentStatus = "UnPaid";
                                    }
                                    else
                                    {
                                        PaymentStatus = paypalAutoPaymentDetail.IsPaid ? "Paid" : "UnPaid";
                                    }

                                    var CarDetail = model.AvailableCars.Where(c => c.Value == garageDefaultSettingByDayCarPaid.EntityTypeValue).SingleOrDefault();
                                    CarDetail.Text += "<br/> <b>Payment Status:</b> " + PaymentStatus;
                                }
                            }
                        }
                    }

                    /// Load Car Payment Detail
                    ///
                    model.CarPayments = new List <CarServicesPayment>();
                    foreach (var car in carList)
                    {
                        CarServicesPayment carPayment = new CarServicesPayment();
                        carPayment.CarId         = car.CarId;
                        carPayment.DisplayName   = car.DisplayName;
                        carPayment.LicenseNumber = car.LicenseNumber;
                        carPayment.Make          = car.Make;
                        carPayment.Color         = car.Color;

                        var garageDefaultSettingByDayCarPaid = garageDefaultSettingByDay.Where(f => f.EntityTypeKey == (int)EntityTypeKey.Car && f.EntityTypeValue == car.CarId.ToString()).SingleOrDefault();
                        carPayment.ServiceDayId = garageDefaultSettingByDayCarPaid.Id;

                        var userpackageDetail = db.UserPackages.Where(u => u.CarId == car.CarId && u.IsActive == true).SingleOrDefault();
                        if (userpackageDetail != null)
                        {
                            string PaymentStatus           = string.Empty;
                            var    paypalAutoPaymentDetail = db.PaypalAutoPayments.Where(p => p.UserPackageID == userpackageDetail.Id && p.ServiceDate == model.ServiceDate).FirstOrDefault();

                            if (paypalAutoPaymentDetail == null)
                            {
                                carPayment.IsPaid = false;
                            }
                            else
                            {
                                carPayment.IsPaid = paypalAutoPaymentDetail.IsPaid ? true : false;
                            }
                        }


                        model.CarPayments.Add(carPayment);
                    }

                    /// Load Car With Services
                    ///

                    model.CarServicesList = new List <CarServices>();
                    foreach (var car in carList)
                    {
                        foreach (var team in TeamList)
                        {
                            bool selected = garageDefaultSettingByDay.Find(f => f.EntityTypeKey == (int)EntityTypeKey.Car && f.EntityTypeValue == car.CarId.ToString() && f.GarageTeamId == team.Id) != null;
                            if (selected)
                            {
                                CarServices carService = new CarServices();
                                carService.CarDisplayName = car.DisplayName;
                                carService.CarId          = car.CarId;
                                carService.TeamId         = team.Id;


                                var pCarId = new SqlParameter();
                                pCarId.ParameterName = "CarId";
                                pCarId.Value         = car.CarId;
                                pCarId.DbType        = DbType.Int32;

                                var servicesList = db.Database.SqlQuery <GreenPro.Data.Service>(
                                    "EXEC dbo.GetServicesByCarId @CarId",
                                    pCarId
                                    ).ToList();

                                if (servicesList.Count > 0)
                                {
                                    carService.SelectServices = new List <CarServices.SelectService>();
                                    foreach (var service in servicesList)
                                    {
                                        CarServices.SelectService seviceModel = new CarServices.SelectService();
                                        seviceModel.ServiceName = service.Service_Name;
                                        carService.SelectServices.Add(seviceModel);
                                    }
                                }

                                model.CarServicesList.Add(carService);
                            }
                        }
                    }
                }
            }
            else if (garageDefaultSettingEitity != null)
            {
                var garageDefaultSettingByDay = garageDefaultSettingEitity.Where(q => q.ServiceDay == model.ServiceDay).ToList();

                if (garageDefaultSettingByDay.Count > 0)
                {
                    // load existing leaders
                    foreach (var leader in LeadersList)
                    {
                        foreach (var team in TeamList)
                        {
                            bool selected = garageDefaultSettingByDay.Find(f => f.EntityTypeKey == (int)EntityTypeKey.Leader && f.EntityTypeValue == leader.Id && f.GarageTeamId == team.Id) != null;
                            if (!model.SelectedLeaders.ContainsKey(leader.Id))
                            {
                                model.SelectedLeaders[leader.Id] = new Dictionary <int, bool>();
                            }
                            model.SelectedLeaders[leader.Id][team.Id] = selected;
                        }
                    }

                    // load existing member
                    foreach (var leader in memberList)
                    {
                        foreach (var team in TeamList)
                        {
                            bool selected = garageDefaultSettingByDay.Find(f => f.EntityTypeKey == (int)EntityTypeKey.Member && f.EntityTypeValue == leader.Id && f.GarageTeamId == team.Id) != null;
                            if (!model.SelectedMembers.ContainsKey(leader.Id))
                            {
                                model.SelectedMembers[leader.Id] = new Dictionary <int, bool>();
                            }
                            model.SelectedMembers[leader.Id][team.Id] = selected;
                        }
                    }


                    // load existing cars
                    foreach (var car in carList)
                    {
                        foreach (var team in TeamList)
                        {
                            bool selected = garageDefaultSettingByDay.Find(f => f.EntityTypeKey == (int)EntityTypeKey.Car && f.EntityTypeValue == car.CarId.ToString() && f.GarageTeamId == team.Id) != null;
                            if (!model.SelectedCars.ContainsKey(car.CarId))
                            {
                                model.SelectedCars[car.CarId] = new Dictionary <int, bool>();
                            }
                            model.SelectedCars[car.CarId][team.Id] = selected;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public ActionResult CurrentCarServiceDetail(int Id)
        {
            CurrentCarServiceDetailModel model = new CurrentCarServiceDetailModel();

            // Get Car Information
            var CarServiceDetail = db.Garage_CarDaySetting.Where(q => q.Id == Id &&
                                                                 q.EntityTypeKey == (int)EntityTypeKey.Car
                                                                 ).SingleOrDefault();

            if (CarServiceDetail == null)
            {
                return(RedirectToAction("Index"));
            }
            model.CurrentCarServiceId = Id;
            int carId  = Convert.ToInt32(CarServiceDetail.EntityTypeValue);
            var aspCar = db.CarUsers.Where(c => c.CarId == carId).SingleOrDefault();

            if (aspCar != null)
            {
                model.CarService = new CarServices()
                {
                    ServiceDayId   = CarServiceDetail.Id,
                    CarId          = aspCar.CarId,
                    CarDisplayName = aspCar.DisplayName,
                    Make           = aspCar.Make,
                    PurchaseYear   = aspCar.PurchaseYear,
                    Color          = aspCar.Color,
                    LicenseNumber  = aspCar.LicenseNumber,
                    serviceStatus  = (ServiceStatus)CarServiceDetail.ServiceStatusId,
                    //ServiceStatusId = CarServiceDetail.ServiceStatusId,
                };
                model.ServiceStatusId = CarServiceDetail.ServiceStatusId;

                if (CarServiceDetail.StartTime.HasValue)
                {
                    model.StartDateTime = CarServiceDetail.StartTime;
                }

                if (CarServiceDetail.EndTime.HasValue)
                {
                    model.EndDateTime = CarServiceDetail.EndTime;
                }

                model.Comment = CarServiceDetail.Comment;

                // Get Car Services Information
                model.CarService.SelectServices = new List <CarServices.SelectService>();
                var pCarId = new SqlParameter();
                pCarId.ParameterName = "CarId";
                pCarId.Value         = aspCar.CarId;
                pCarId.DbType        = DbType.Int32;

                var servicesList = db.Database.SqlQuery <GreenPro.Data.Service>(
                    "EXEC dbo.GetServicesByCarId @CarId",
                    pCarId
                    ).ToList();

                if (servicesList.Count > 0)
                {
                    foreach (var service in servicesList)
                    {
                        CarServices.SelectService seviceModel = new CarServices.SelectService();
                        seviceModel.ServiceName = service.Service_Name;
                        model.CarService.SelectServices.Add(seviceModel);
                    }
                }
            }

            model.AvailableServiceStatus = ListHelper.GetServiceStatusList();



            return(View(model));
        }