示例#1
0
        public void Save(VehicleDocumentItem model)
        {
            VehicleDocument objVehicleDoc = new VehicleDocument();

            objVehicleDoc.FileName    = model.FileName;
            objVehicleDoc.FileUrl     = model.FileUrl;
            objVehicleDoc.VId         = model.VId;
            objVehicleDoc.Status      = "Active";
            objVehicleDoc.CreatedDate = System.DateTime.Now;
            DbContext.VehicleDocuments.Add(objVehicleDoc);
            DbContext.SaveChanges();
        }
示例#2
0
        public ActionResult Edit(VehicleItem model, HttpPostedFileBase[] files)
        {
            //    int Empid = Convert.ToInt32(Url.RequestContext.RouteData.Values["id"].ToString());
            //model.EmpID = Empid;
            VehicleMasterService objVservice = new VehicleMasterService();
            string uid = null;

            if (Session["UserId"] != null)
            {
                uid = Session["UserId"].ToString();
            }

            model.UpdatedBy = uid;
            model.UpdatedOn = System.DateTime.Now;
            objVservice.Update(model, model.PCardItem);

            VehicleDocumentItem  objVehicleItem = new VehicleDocumentItem();
            VehicleMasterService obj            = new VehicleMasterService();


            if (files != null)
            {
                string s       = Convert.ToString(model.VID);
                string strtext = "Vehicle";
                foreach (HttpPostedFileBase file in files)
                {
                    if (file != null)
                    {
                        string filename   = System.IO.Path.GetFileName(file.FileName);
                        string folderPath = Server.MapPath("~/UploadedDocs/") + strtext;
                        //  obj.EmpId = Convert.ToInt32(Url.RequestContext.RouteData.Values["id"].ToString());
                        string destinationPath    = folderPath;
                        string employeeFolderPath = destinationPath + "/" + s;
                        // create folder if it is not exist
                        if (!Directory.Exists(folderPath))
                        {
                            Directory.CreateDirectory(folderPath);
                            if (!Directory.Exists(employeeFolderPath))
                            {
                                Directory.CreateDirectory(employeeFolderPath);
                                // create emp id folder of not exist
                            }
                        }
                        else
                        {
                            if (!Directory.Exists(employeeFolderPath))
                            {
                                Directory.CreateDirectory(employeeFolderPath);
                                // create emp id folder of not exist
                            }
                        }
                        destinationPath = employeeFolderPath;
                        /*Saving the file in server folder*/
                        //file.SaveAs(Server.MapPath("~/Images/" + filename));
                        string fileNewName = Guid.NewGuid() + Path.GetExtension(file.FileName);

                        file.SaveAs(Path.Combine(destinationPath, fileNewName));
                        objVehicleItem.UpdatedBy   = uid;
                        objVehicleItem.UpdatedDate = System.DateTime.Now;
                        objVehicleItem.VId         = Convert.ToInt32(s);
                        objVehicleItem.FileUrl     = Path.Combine("/UploadedDocs/" + strtext + "/" + s + "/", fileNewName);
                        objVehicleItem.FileName    = Path.GetFileNameWithoutExtension(file.FileName);
                        obj.Save(objVehicleItem);
                        //string filepathtosave = "Images/" + filename;
                        /*HERE WILL BE YOUR CODE TO SAVE THE FILE DETAIL IN DATA BASE*/
                    }
                }
            }

            return(RedirectToAction("Edit", new { @menuId = model.Viewbagidformenu }));
        }