Esempio n. 1
0
        public JsonResult ManageSiteTaskInventory(string Filter, List <PM_SiteTaskInventory> STI_List, long SiteTaskId, long SiteId, long UserId)
        {
            PM_TaskEntryBL te  = new PM_TaskEntryBL();
            dbDataTable    ddt = new dbDataTable();

            DataTable dt = ddt.List();

            foreach (var item in STI_List)
            {
                myDataTable.AddRow(dt, "Value1", item.SiteTaskId, "Value2", item.CategoryId, "Value3", item.SiteId, "Value4", item.SiteTaskInventoryId, "Value5", item.IsModified, "Value6", item.ItemId, "Value7", item.Quantity, "Value8", item.BarCode, "Value11", item.Description);
            }

            DataTable res = te.Manage_SiteTask_Inventory(Filter, dt, SiteTaskId, SiteId, UserId);

            // Update Attachments Directory
            if (res.Rows.Count > 0)
            {
                for (int i = 0; i < res.Rows.Count; i++)
                {
                    var ExistingPath = res.Rows[i]["SubDirectory"].ToString();
                    var NewPath      = res.Rows[i]["InventoryId"].ToString();
                    SWI.AirView.Common.WebConfig wc = new SWI.AirView.Common.WebConfig();
                    var SiteTaskInventoryPath       = wc.AppSettings("SiteTaskInventoryPath");

                    var path = Path.Combine(Server.MapPath("~/" + SiteTaskInventoryPath + "/" + ExistingPath));

                    string pathString = System.IO.Path.Combine(path.ToString());
                    bool   isExists   = System.IO.Directory.Exists(pathString);

                    string NewPathString = (Path.Combine(Server.MapPath("~/" + SiteTaskInventoryPath + "/" + NewPath))).ToString();

                    if (isExists)
                    {
                        System.IO.Directory.Move(pathString, NewPathString);
                    }
                }
            }
            Response response = new Response();

            try
            {
                response.Status  = "success";
                response.Message = "Save successfully";
            }
            catch (Exception ex)
            {
                response.Status  = "danger";
                response.Message = ex.Message;
            }


            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public JsonResult RemoveSiteTaskInventory(string Filter, int SiteTaskInventoryId, long CategoryId, long ItemId, string FileName)
        {
            PM_TaskEntryBL te = new PM_TaskEntryBL();

            try
            {
                if (Filter == "DeleteAttachmentById")
                {
                    SWI.AirView.Common.WebConfig wc = new SWI.AirView.Common.WebConfig();
                    var SiteTaskInventoryPath       = wc.AppSettings("SiteTaskInventoryPath");
                    var SubDirectory = "";
                    if (SiteTaskInventoryId != 0)
                    {
                        SubDirectory = SiteTaskInventoryId.ToString();
                    }
                    else
                    {
                        SubDirectory = (CategoryId + "_" + ItemId).ToString();
                    }

                    var path = Path.Combine(Server.MapPath("~/" + SiteTaskInventoryPath + "/" + SubDirectory));
                    try
                    {
                        if ((System.IO.File.Exists(path + "/" + FileName)))
                        {
                            System.IO.File.Delete(path + "/" + FileName);
                        }
                        System.IO.DirectoryInfo di = new DirectoryInfo(path);
                        if (di.GetFiles().Length == 0)
                        {
                            System.IO.Directory.Delete(path, true);
                        }
                    }
                    catch {}
                    te.Manage_SiteTask_Inventory("DeleteAttachmentById", null, 0, 0, 0, SiteTaskInventoryId, FileName, SubDirectory, 0);
                }
                else
                {
                    SWI.AirView.Common.WebConfig wc = new SWI.AirView.Common.WebConfig();
                    var SiteTaskInventoryPath       = wc.AppSettings("SiteTaskInventoryPath");
                    var SubDirectory = "";
                    if (SiteTaskInventoryId != 0)
                    {
                        SubDirectory = SiteTaskInventoryId.ToString();
                    }
                    else
                    {
                        SubDirectory = (CategoryId + "_" + ItemId).ToString();
                    }

                    var path = Path.Combine(Server.MapPath("~/" + SiteTaskInventoryPath + "/" + SubDirectory));
                    try
                    {
                        if (System.IO.Directory.Exists(path))
                        {
                            System.IO.DirectoryInfo di = new DirectoryInfo(path);

                            foreach (FileInfo file in di.GetFiles())
                            {
                                file.Delete();
                            }
                            System.IO.Directory.Delete(path, true);
                        }
                    }
                    catch { }
                    te.Manage_SiteTask_Inventory("DeleteSiteTaskInventory", null, 0, 0, 0, SiteTaskInventoryId, FileName, SubDirectory, 0);
                }
            }
            catch
            {
            }
            Response res = new Response()
            {
                Message = "Removed!",
                Status  = "success"
            };

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public ActionResult UploadAttachments(int SiteTaskInventoryId, long CategoryId, long ItemId)
        {
            PM_TaskEntryBL te = new PM_TaskEntryBL();
            bool           isSavedSuccessfully = true;
            string         fName        = "";
            string         SubDirectory = "";

            try
            {
                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    fName = file.FileName;
                    if (file != null && file.ContentLength > 0)
                    {
                        SWI.AirView.Common.WebConfig wc = new SWI.AirView.Common.WebConfig();
                        var SiteTaskInventoryPath       = wc.AppSettings("SiteTaskInventoryPath");
                        if (SiteTaskInventoryId == 0)
                        {
                            SubDirectory = (CategoryId + "_" + ItemId).ToString();
                        }
                        else
                        {
                            SubDirectory = SiteTaskInventoryId.ToString();
                        }
                        var    path       = Path.Combine(Server.MapPath("~/" + SiteTaskInventoryPath + "/" + SubDirectory));
                        string pathString = System.IO.Path.Combine(path.ToString());
                        var    fileName1  = Path.GetFileName(file.FileName);
                        bool   isExists   = System.IO.Directory.Exists(pathString);
                        if (!isExists)
                        {
                            System.IO.Directory.CreateDirectory(pathString);
                        }
                        var uploadpath = string.Format("{0}\\{1}", pathString, file.FileName);
                        file.SaveAs(uploadpath);
                        DataTable res = te.Manage_SiteTask_Inventory("Add_Attachments", null, 0, 0, 0, SiteTaskInventoryId, file.FileName, SubDirectory, file.ContentLength);
                        if (res.Rows.Count == 0)
                        {
                            isSavedSuccessfully = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                isSavedSuccessfully = false;
            }
            if (isSavedSuccessfully)
            {
                return(Json(new
                {
                    Message = fName
                }));
            }
            else
            {
                return(Json(new
                {
                    Message = "Error in saving file"
                }));
            }
        }