Пример #1
0
        public static List<WOTemplateFileDetails> GetDocumentFiles(string @FileIds)
        {
            var data = new List<WOTemplateFileDetails>();
            tempinfo objtempinfo = new tempinfo();
            SqlParameter[] sqlParams = new SqlParameter[1];

            sqlParams[0] = new SqlParameter("@FileIds", @FileIds);

            var reader = SqlHelper.ExecuteReader(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "[SpGetDocumentFiles]", sqlParams);
            var safe = new SafeDataReader(reader);
            while (reader.Read())
            {
                var Template = new WOTemplateFileDetails();
                FetchTemplate(Template, safe);
                data.Add(Template);
            }

            return data;
        }
Пример #2
0
        /// <summary>
        /// Description   : Method is used to Insert new template details.
        /// Created By    : Sudheer 
        /// Created Date  : 26th Aug 2014
        /// Modified By   : Sudheer          
        /// <returns></returns>
        /// </summary>
        public static int InsertTemplateFileDetails(WOTemplateFileDetails arrFilesList, string flag, string fieldID, string CreatedBy)
        {
            int result = 0;
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            try
            {
                SqlParameter[] sqlParams = new SqlParameter[12];
                sqlParams[0] = new SqlParameter("@SetID", Convert.ToInt32(arrFilesList.SetID));
                sqlParams[1] = new SqlParameter("@DisplayName", arrFilesList.DisplayName);
                sqlParams[2] = new SqlParameter("@FileName", arrFilesList.FileName);
                sqlParams[3] = new SqlParameter("@FilePath", arrFilesList.FilePath);
                sqlParams[4] = new SqlParameter("@Description", arrFilesList.Description);
                sqlParams[5] = new SqlParameter("@Status", Convert.ToBoolean(arrFilesList.Status));
                sqlParams[6] = new SqlParameter("@IsDefault", Convert.ToBoolean(arrFilesList.IsDefault));
                sqlParams[7] = new SqlParameter("@IsMultiple", Convert.ToBoolean(arrFilesList.IsMultiple));
                sqlParams[8] = new SqlParameter("@MultipleEntity", arrFilesList.MultipleEntity);
                sqlParams[9] = new SqlParameter("@Flag", flag);
                sqlParams[10] = new SqlParameter("@FieldID", fieldID);
                sqlParams[11] = new SqlParameter("@CreatedBy", CreatedBy);
                result = SqlHelper.ExecuteNonQuery(ConnectionUtility.GetConnectionString(), CommandType.StoredProcedure, "SpInsertTemplateFileDetails", sqlParams);
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex);
            }
            log.Debug("End: " + methodBase.Name);

            return result;
        }
Пример #3
0
        public static WOTemplateFileDetails FetchTemplate(WOTemplateFileDetails TMapping, SafeDataReader dr)
        {
            TMapping.FileName = dr.GetString("FileName");
            TMapping.FilePath = dr.GetString("FilePath");
            TMapping.IsDefault = dr.GetBoolean("IsDefault");
            TMapping.IsMultiple = dr.GetBoolean("IsMultiple");
            TMapping.MultipleEntity = dr.GetString("MultipleEntity");

            return TMapping;
        }
        public ActionResult FileUpload(string Type, string Category, string TemplateDetails)
        {
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
            System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
            log.Debug("Start: " + methodBase.Name);
            try
            {
                if (UserLogin.ValidateUserRequest())
                {
                    return RedirectToAction("Login", "Home", new { area = "" });
                }

                string UserIDSession = Convert.ToString(System.Web.HttpContext.Current.Session["UserID"]);

                var json_serializer = new JavaScriptSerializer();
                Dictionary<string, object> routes_list = (Dictionary<string, object>)json_serializer.DeserializeObject(TemplateDetails);
                Dictionary<string, object> a = (Dictionary<string, object>)routes_list["TemplateDetails"];
                WOTemplateFileDetails arrFilesList = new WOTemplateFileDetails();

                arrFilesList.SetID = Convert.ToString(a["SetID"]);
                arrFilesList.DisplayName = Convert.ToString(a["DisplayName"]);
                arrFilesList.FilePath = Convert.ToString(a["FilePath"]);
                arrFilesList.Description = Convert.ToString(a["Description"]);
                arrFilesList.Status = Convert.ToString(a["Status"]);
                arrFilesList.IsDefault = Convert.ToBoolean(a["IsDefault"]);
                arrFilesList.IsMultiple = Convert.ToBoolean(a["IsMultiple"]);
                arrFilesList.MultipleEntity = (arrFilesList.IsMultiple == true ? Convert.ToString(a["MultipleEntity"]) : "");
                arrFilesList.FileName = Convert.ToString(a["FileName"]);

                string OldFilePath = string.Format("{0}{1}", Server.MapPath(arrFilesList.FilePath + "/"), arrFilesList.FileName);

                string flag = Convert.ToString(a["Flag"]);
                string fieldID = Convert.ToString(a["FieldID"]);

                if (Request.Files["file"].ContentLength > 0 && !string.IsNullOrEmpty(arrFilesList.FilePath))
                {
                    string extension = System.IO.Path.GetExtension(Request.Files["file"].FileName);
                    string path = string.Empty;
                    if (extension.ToUpper() == ".DOCX" || extension.ToUpper() == ".DOC")
                    {
                        try
                        {
                            //string FileName = System.IO.Path.GetFileNameWithoutExtension(Request.Files["file"].FileName) + DateTime.Now.Ticks + extension;
                            string FileName = System.IO.Path.GetFileNameWithoutExtension(arrFilesList.DisplayName) + "_" + DateTime.Now.ToString("dd_MMM_yyyy_hh_mm_ss") + extension;
                            path = string.Format("{0}{1}", Server.MapPath(arrFilesList.FilePath + "/"), FileName);
                            //File Name for Insert New record
                            arrFilesList.FileName = FileName;

                            Request.Files["file"].SaveAs(path);
                            TempData["FileName"] = FileName + "|" + Type;
                            TempData["Message"] = "FileUploaded" + "|" + Type + "|" + Category;
                            if (TemplateMapping.InsertTemplateFileDetails(arrFilesList, flag, fieldID, UserIDSession) == 1) //Success
                            {
                                if (System.IO.File.Exists(OldFilePath))
                                    System.IO.File.Delete(OldFilePath);
                            }
                            else
                            {
                                TempData["AlertMessage"] = "error";
                                if (System.IO.File.Exists(path))
                                    System.IO.File.Delete(path);
                            }

                        }
                        catch (Exception)
                        {
                            TempData["AlertMessage"] = "error";
                            if (System.IO.File.Exists(path))
                                System.IO.File.Delete(path);
                        }

                    }
                    else
                        TempData["Message"] = "FileNotValid|" + Type + "|" + Category;

                }
                else if (flag == "Edit")
                {
                    TemplateMapping.InsertTemplateFileDetails(arrFilesList, flag, fieldID, UserIDSession);
                    TempData["Message"] = "FileUploaded|" + Type + "|" + Category;
                }
                else
                    TempData["Message"] = "FileNotValid|" + Type + "|" + Category;

                return RedirectToAction("ManageTemplate");

            }
            catch (Exception ex)
            {
                TempData["AlertMessage"] = "error";
                log.Error("Error: " + ex);
                return RedirectToAction("ManageTemplate");
            }
            finally
            {
                log.Debug("End: " + methodBase.Name);
            }
        }