Esempio n. 1
0
        public ActionResult AddMasterData(int MasterType, int ParentID, string MasterData)
        {
            DBModels.BeeServiceEntities2 context = new DBModels.BeeServiceEntities2();

            try
            {

                switch (MasterType)
                {
                    case 0: //Vehicles
                        ClientVehicleType vType = (ClientVehicleType)JsonConvert.DeserializeObject(MasterData, typeof(ClientVehicleType));
                        DBModels.VehicleType vehType = new DBModels.VehicleType();
                        vehType.TYPE = vType.Type;
                        context.VehicleTypes.Add(vehType);
                        break;
                    case 1: //Veh Class
                        ClientVehicleClass vClass = (ClientVehicleClass)JsonConvert.DeserializeObject(MasterData, typeof(ClientVehicleClass));
                        DBModels.VehicleClass vehClass = new DBModels.VehicleClass();
                        vehClass.VehichleTypeID = ParentID;
                        vehClass.Class = vClass.Name;
                        context.VehicleClasses.Add(vehClass);
                        break;
                    case 2: //Service Type
                        ClientServiceType sType = (ClientServiceType)JsonConvert.DeserializeObject(MasterData, typeof(ClientServiceType));
                        DBModels.ServiceType serType = new DBModels.ServiceType();
                        serType.VehicleClassID = ParentID;
                        serType.ServiceType1 = sType.Name;
                        serType.Duration = sType.Duration;
                        serType.Cost = sType.Cost;
                        context.ServiceTypes.Add(serType);
                        break;
                    case 3: //Addon
                        ClientAddon addon = (ClientAddon)JsonConvert.DeserializeObject(MasterData, typeof(ClientAddon));
                        //"{\"name\":\"fff\",\"duration\":30,\"cost\":5}"
                        DBModels.AddOn Addon = new DBModels.AddOn();
                        Addon.ServiceTypeID = ParentID;
                        Addon.AddOn1 = addon.Name;
                        Addon.Cost = addon.Cost;
                        Addon.Duration = addon.Duration;
                        context.AddOns.Add(Addon);
                        break;
                    default:
                        break;
                }
                context.SaveChanges();
                return RedirectToAction("ManageServiceRequests");
            }
            catch (Exception e)
            {
                string strMessage = "{\"success\": 0, \"message\": \"Failed to save the service request. (" + e.Message + ")\"}";
                return Json(strMessage, JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 2
0
        public ActionResult DelayServiceRequests(int[] serviceRequestIds)
        {
            if (serviceRequestIds == null)
                return Json(new { success = "false" }); ;

            List<int> serRequestIdsList = new List<int>(serviceRequestIds);
            DBModels.BeeServiceEntities2 context = new DBModels.BeeServiceEntities2();
            List<Data.ServiceRequest> serviceRequests = context.ServiceRequests.Where(x => serRequestIdsList.Contains(x.ID)).ToList();
            List<DateTime> days = new List<DateTime>();
            //Dictionary<DateTime, Data.ServiceRequest> delayDayRequestsMap = new Dictionary<DateTime, DBModels.ServiceRequest>();
            foreach (var serviceRequest in serviceRequests)
            {
                days.Add(serviceRequest.ServiceStartTime.Date);
            };
            foreach (DateTime day in days)
            {
                List<Data.ServiceRequest> allDayServiceRequests = context.ServiceRequests.Where(x => DbFunctions.TruncateTime(x.ServiceStartTime) == day.Date).OrderBy(x => x.ServiceTeamID).ThenBy(x => x.ServiceStartTime).ToList();
                int lastTeamId = 0;
                DateTime lastReqEndTime = DateTime.MinValue;
                foreach (var serviceRequest in allDayServiceRequests)
                {
                    if (lastTeamId != serviceRequest.ServiceTeamID)
                    {
                        lastTeamId = (int)serviceRequest.ServiceTeamID;
                        lastReqEndTime = DateTime.MinValue;
                    }
                    if (serRequestIdsList.Contains(serviceRequest.ID))
                    {
                        serviceRequest.ServiceStartTime = serviceRequest.ServiceStartTime.AddMinutes(30);
                        serviceRequest.ServiceEndTime = ((DateTime)serviceRequest.ServiceEndTime).AddMinutes(30);

                    }
                    if (DateTime.Compare(lastReqEndTime, serviceRequest.ServiceStartTime) > 0)
                    {
                        TimeSpan span = lastReqEndTime.Subtract(serviceRequest.ServiceStartTime);
                        serviceRequest.ServiceStartTime = lastReqEndTime;
                        serviceRequest.ServiceEndTime = ((DateTime)serviceRequest.ServiceEndTime).AddMinutes(span.Minutes);
                    }
                    lastReqEndTime = (DateTime)serviceRequest.ServiceEndTime;
                };
                context.SaveChanges();
            };
            return Json(new { success = "true" });
        }
Esempio n. 3
0
 public ActionResult CancelServiceRequest(int serviceRequestId)
 {
     DBModels.BeeServiceEntities2 context = new DBModels.BeeServiceEntities2();
     Data.ServiceRequest serRequest = context.ServiceRequests.Find(serviceRequestId);
     context.ServiceRequests.Remove(serRequest);
     context.SaveChanges();
     return RedirectToAction("ListServiceRequests");
 }
Esempio n. 4
0
 public ActionResult UpdateServiceRequestStatus(int serviceRequestId, short status)
 {
     DBModels.BeeServiceEntities2 context = new DBModels.BeeServiceEntities2();
     Data.ServiceRequest serRequest = context.ServiceRequests.Find(serviceRequestId);
     serRequest.Status = status;
     context.SaveChanges();
     return RedirectToAction("ManageServiceRequests");
 }
Esempio n. 5
0
        public ActionResult UpdateMasterDataStatus(int MasterType, int MasterID, short Status)
        {
            DBModels.BeeServiceEntities2 context = new DBModels.BeeServiceEntities2();
            switch (MasterType)
            {
                case 0: //Vehicles
                    Data.VehicleType vehType = context.VehicleTypes.Find(MasterID);
                    vehType.Status = Status;
                    break;
                case 1: //Veh Class
                    Data.VehicleClass vehClass = context.VehicleClasses.Find(MasterID);
                    vehClass.Status = Status;
                    break;
                case 2: //Veh Class
                    Data.ServiceType serType = context.ServiceTypes.Find(MasterID);
                    serType.Status = Status;
                    break;
                case 3: //Veh Class
                    Data.AddOn Addon = context.AddOns.Find(MasterID);
                    Addon.Status = Status;
                    break;
                case 4: //Veh Class
                    Data.ServiceTeam serTeam = context.ServiceTeams.Find(MasterID);
                    serTeam.Status = Status;
                    break;
                case 5: //Veh Class
                    Data.Landmark landmark = context.Landmarks.Find(MasterID);
                    landmark.Status = Status;
                    break;
                default:
                    break;
            }

            context.SaveChanges();
            return RedirectToAction("ManageServiceRequests");
        }
Esempio n. 6
0
        public JsonResult SaveServiceRequest(ServiceRequest SRequest)
        {
            string strMessage;
            string strPassword = "";
            string strMailBody = "Your service request has been registered successfully. Please login using your emailid.";
            try
            {
                DBModels.BeeServiceEntities2 context = new DBModels.BeeServiceEntities2();
                DBModels.ServiceRequest serviceRequest;
                int TotalDuration = 0;
                decimal TotalCost = 0;
                int serviceTeamID = 0;

                if (SRequest.ID != 0)
                {
                    serviceRequest = context.ServiceRequests.Where(a => a.ID.Equals(SRequest.ID)).FirstOrDefault();
                    while (serviceRequest.ServiceRequestVehicles.Any())
                    {
                        Data.ServiceRequestVehicle objServiceRequestVehicle = serviceRequest.ServiceRequestVehicles.First();
                        while (objServiceRequestVehicle.ServiceAddOns.Any())
                            context.ServiceAddOns.Remove(objServiceRequestVehicle.ServiceAddOns.First());
                        context.ServiceRequestVehicles.Remove(objServiceRequestVehicle);
                    }
                }
                else
                {
                    serviceRequest = new DBModels.ServiceRequest();
                    if (SRequest.BeeUser.Id != 0)
                    {
                        serviceRequest.BeeUser = context.BeeUsers.Where(a => a.Id.Equals(SRequest.BeeUser.Id)).FirstOrDefault();
                    }
                    else
                    {
                        serviceRequest.BeeUser = new Data.BeeUser();
                        if (isEmailDuplicate(SRequest.BeeUser.Email))
                        {
                            serviceRequest.BeeUser = context.BeeUsers.Where(a => a.Email.Equals(SRequest.BeeUser.Email)).FirstOrDefault();
                            SRequest.BeeUser.Id = serviceRequest.BeeUser.Id;
                        }
                    }
                }

                serviceRequest.ServiceStartTime = SRequest.StartTime;
                serviceRequest.Status = 0; //Service request in pending state
                serviceRequest.BeeUser.Address = SRequest.BeeUser.Address;
                serviceRequest.BeeUser.ContactPreference = SRequest.BeeUser.ContactPreference;
                serviceRequest.BeeUser.LandmarkID = SRequest.BeeUser.LandmarkID;
                serviceRequest.BeeUser.Message = SRequest.BeeUser.Message;
                serviceRequest.BeeUser.PaymentMode = SRequest.BeeUser.PaymentMode;
                serviceRequest.BeeUser.Phone = SRequest.BeeUser.Phone;
                serviceRequest.BeeUser.TextNotifications = SRequest.BeeUser.TextNotifications;
                if (SRequest.BeeUser.Id == 0)
                {
                    serviceRequest.BeeUser.Email = SRequest.BeeUser.Email;
                    serviceRequest.BeeUser.FullName = SRequest.BeeUser.FullName;
                    serviceRequest.BeeUser.RegDate = System.DateTime.Now;
                    strPassword = "******"; // System.Web.Security.Membership.GeneratePassword(8, 0);
                    strMailBody = strMailBody + "Your password is: " + strPassword;
                    serviceRequest.BeeUser.Password = strPassword;
                    serviceRequest.BeeUser.Username = "";
                }

                foreach (var SRVehicle in SRequest.ServiceRequestVehicles)
                {
                    var SReqVehicle = new Data.ServiceRequestVehicle();
                    TotalDuration = TotalDuration + (int)context.ServiceTypes.Find(SRVehicle.ServiceTypeID).Duration;
                    TotalCost = TotalCost + context.ServiceTypes.Find(SRVehicle.ServiceTypeID).Cost.Value;
                    SReqVehicle.VehicleClassID = SRVehicle.VehicleClassID;
                    SReqVehicle.ServiceTypeID = SRVehicle.ServiceTypeID;
                    SReqVehicle.VehicleTypeID = SRVehicle.VehicleTypeID;
                    if (SRVehicle.VehicleAddonIDs != null)
                    {
                        foreach (int SRAddOnID in SRVehicle.VehicleAddonIDs)
                        {
                            if (SRAddOnID != 0)
                            {
                                var SReqAddon = new Data.ServiceAddOn();
                                SReqAddon.AddOnID = SRAddOnID;
                                SReqVehicle.ServiceAddOns.Add(SReqAddon);
                                TotalCost = TotalCost + context.AddOns.Find(SRAddOnID).Cost.Value;
                                TotalDuration = TotalDuration + (int)context.AddOns.Find(SRAddOnID).Duration;
                            }
                        }
                    }
                    serviceRequest.ServiceRequestVehicles.Add(SReqVehicle);
                }
                TotalDuration = TotalDuration + 30;
                serviceRequest.ServiceDuration = TotalDuration; //Service request in pending state
                serviceRequest.ServiceCost = TotalCost;
                serviceRequest.ServiceEndTime = SRequest.StartTime.AddMinutes(TotalDuration);
                serviceTeamID = getAvailableServiceTeam(SRequest.StartTime, SRequest.StartTime.AddMinutes(TotalDuration));
                if (serviceTeamID == 0)
                    throw new ServiceException("No service team available for the specified time");

                serviceRequest.ServiceTeamID = serviceTeamID;
                if (SRequest.ID == 0)
                    context.ServiceRequests.Add(serviceRequest);

                context.SaveChanges();
            //temporarily disabled email functionality
            //                if (SRequest.ID == 0)
            //                    sendMail(SRequest.BeeUser.Email, strMailBody);
            }
            catch (Exception e)
            {
                strMessage = "{\"success\": 0, \"message\": \"Failed to save the service request. (" + e.Message + ")\"}";
                return Json(strMessage, JsonRequestBehavior.AllowGet);
            }
            finally
            {
                //sendMail(BuildServiceDetails(serviceRequest.ID));
            }
            strMessage = ("{\"success\": 1, \"message\": \"Service request registered successfully\"}");
            return Json(strMessage, JsonRequestBehavior.AllowGet);
        }