Esempio n. 1
0
        public string SaveUpdateVehicle(VehicleModel model)
        {
            ShomaRMEntities db             = new ShomaRMEntities();
            string          msg            = "";
            int             userid         = ShomaRM.Models.ShomaGroupWebSession.CurrentUser != null ? ShomaRM.Models.ShomaGroupWebSession.CurrentUser.UserID : 0;
            var             tenantProperty = db.tbl_ApplyNow.Where(p => p.ID == model.TenantID).FirstOrDefault();
            var             propertyUnit   = db.tbl_PropertyUnits.Where(p => p.UID == tenantProperty.PropertyId).FirstOrDefault();
            int?            TotalSpace     = 0;
            int?            newAvailSpace  = 0;

            if (tenantProperty != null)
            {
                if (propertyUnit != null)
                {
                    if (propertyUnit.Bedroom == 1)
                    {
                        newAvailSpace = 1;
                    }
                    else if (propertyUnit.Bedroom == 2)
                    {
                        newAvailSpace = 1;
                    }
                    else if (propertyUnit.Bedroom == 3)
                    {
                        newAvailSpace = 2;
                    }
                    TotalSpace = tenantProperty.AdditionalParking + newAvailSpace;
                }
            }

            var availableList = db.tbl_Vehicle.Where(p => p.TenantID == model.TenantID).ToList();


            if (availableList.Count < TotalSpace)
            {
                if (model.Vehicle_ID == 0)
                {
                    var saveVehicle = new tbl_Vehicle()
                    {
                        VehicleRegistration = model.VehicleRegistration,
                        OriginalVehicleReg  = model.OriginalVehicleRegistation,
                        Vehicle_ID          = model.Vehicle_ID,
                        TenantID            = model.TenantID,
                        Make        = model.Make,
                        Model       = model.VModel,
                        Year        = model.Year,
                        Color       = model.Color,
                        License     = model.License,
                        State       = model.State,
                        OwnerName   = model.OwnerName,
                        Notes       = model.Notes,
                        Tag         = model.Tag,
                        ParkingID   = model.ParkingID,
                        AddedBy     = userid,
                        VehicleType = model.VehicleType
                    };
                    db.tbl_Vehicle.Add(saveVehicle);
                    db.SaveChanges();

                    var ParkingInfo = db.tbl_Parking.Where(p => p.ParkingID == model.ParkingID).FirstOrDefault();
                    ParkingInfo.Status  = 1;
                    ParkingInfo.AddedBy = userid;
                    db.SaveChanges();
                    msg = "Vehicle Saved Successfully";
                }
            }
            else
            {
                msg = "You can not add Vehicle Due to Un-available Vehicle Space";
            }
            if (model.Vehicle_ID != 0)
            {
                var getVehdata = db.tbl_Vehicle.Where(p => p.Vehicle_ID == model.Vehicle_ID).FirstOrDefault();
                if (getVehdata != null)
                {
                    getVehdata.VehicleRegistration = model.VehicleRegistration;
                    getVehdata.OriginalVehicleReg  = model.OriginalVehicleRegistation;
                    getVehdata.Vehicle_ID          = model.Vehicle_ID;
                    getVehdata.TenantID            = model.TenantID;
                    getVehdata.Make      = model.Make;
                    getVehdata.Model     = model.VModel;
                    getVehdata.Year      = model.Year;
                    getVehdata.Color     = model.Color;
                    getVehdata.License   = model.License;
                    getVehdata.State     = model.State;
                    getVehdata.OwnerName = model.OwnerName;
                    getVehdata.Notes     = model.Notes;
                    // getVehdata.Tag = model.Tag;
                    getVehdata.ParkingID   = model.ParkingID;
                    getVehdata.VehicleType = model.VehicleType;
                }
                db.SaveChanges();
                msg = "Vehicle Updated Successfully";
            }
            db.Dispose();
            return(msg);
        }
Esempio n. 2
0
        public VehicleModel SaveUploadVehicleRegistation(HttpPostedFileBase fileBaseUploadVehicleRegistation, VehicleModel model)
        {
            ShomaRMEntities db = new ShomaRMEntities();
            VehicleModel    vehicleModelVehicleReg = new VehicleModel();

            string filePath    = "";
            string fileName    = "";
            string sysFileName = "";
            string Extension   = "";

            if (fileBaseUploadVehicleRegistation != null && fileBaseUploadVehicleRegistation.ContentLength > 0)
            {
                filePath = HttpContext.Current.Server.MapPath("~/Content/assets/img/VehicleRegistration/");
                DirectoryInfo di        = new DirectoryInfo(filePath);
                FileInfo      _FileInfo = new FileInfo(filePath);
                if (!di.Exists)
                {
                    di.Create();
                }
                fileName    = fileBaseUploadVehicleRegistation.FileName;
                Extension   = Path.GetExtension(fileBaseUploadVehicleRegistation.FileName);
                sysFileName = DateTime.Now.ToFileTime().ToString() + Path.GetExtension(fileBaseUploadVehicleRegistation.FileName);
                fileBaseUploadVehicleRegistation.SaveAs(filePath + "//" + sysFileName);
                if (!string.IsNullOrWhiteSpace(fileBaseUploadVehicleRegistation.FileName))
                {
                    string afileName = HttpContext.Current.Server.MapPath("~/Content/assets/img/VehicleRegistration/") + "/" + sysFileName;
                }
                vehicleModelVehicleReg.TempVehicleRegistation     = sysFileName.ToString();
                vehicleModelVehicleReg.OriginalVehicleRegistation = fileName;
            }

            return(vehicleModelVehicleReg);
        }