示例#1
0
        public string InsertCategory(CategoryMasterDataModel categoryMasterDataModel, HttpPostedFileBase file)
        {
            string Status      = string.Empty;
            int    Category_Id = 0;

            parameters = new List <KeyValuePair <string, string> >();
            parameters.Add(new KeyValuePair <string, string>("@CategoryId", categoryMasterDataModel.CategoryId.ToString()));
            parameters.Add(new KeyValuePair <string, string>("@CategoryName", categoryMasterDataModel.CategoryName));
            parameters.Add(new KeyValuePair <string, string>("@CategoryShortDescription", categoryMasterDataModel.CategoryShortDescription));
            parameters.Add(new KeyValuePair <string, string>("@CategoryLongDescription", categoryMasterDataModel.CategoryLongDescription));
            parameters.Add(new KeyValuePair <string, string>("@IsActive", categoryMasterDataModel.IsActive.ToString()));
            parameters.Add(new KeyValuePair <string, string>("@CreatedBy", ""));
            parameters.Add(new KeyValuePair <string, string>("@ModifiedBy", ""));
            parameters.Add(new KeyValuePair <string, string>("@CategoryCode", categoryMasterDataModel.CategoryCode));
            var result = CategoryMasterDAL.InsertCategory(parameters);

            if (result != "")
            {
                var statusObj = JObject.Parse(result);
                Status      = (string)statusObj["Status"];
                Category_Id = (int)statusObj["CategoryId"];
            }

            //if (file.FileName != null)
            if (!string.IsNullOrEmpty(file.FileName))
            {
                var ResumefileName = "";

                var Resumepath = "";

                string ResumeDirectory = "";

                string UniqueFilename = "";

                ResumeDirectory = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["CategoryImage"].ToString());

                string[] ext             = ResumefileName.Split('.');
                string   extension       = Path.GetExtension(file.FileName);
                bool     directoryExists = System.IO.Directory.Exists(ResumeDirectory);

                if (!directoryExists)
                {
                    System.IO.Directory.CreateDirectory(ResumeDirectory);
                }
                ResumefileName = categoryMasterDataModel.CategoryName.Substring(0, 3) + "_Img_" + Category_Id + extension;

                Resumepath = Path.Combine(ResumeDirectory, ResumefileName);
                file.SaveAs(Resumepath);

                parameters = new List <KeyValuePair <string, string> >();
                parameters.Add(new KeyValuePair <string, string>("@CategoryId", Convert.ToString(Category_Id)));
                parameters.Add(new KeyValuePair <string, string>("@Filename", ResumefileName));
                CategoryMasterDAL.UpdateCategoryImage(parameters);
            }
            return(Status);
        }
示例#2
0
 public CategoryMasterViewModel()
 {
     category     = new CategoryMasterDataModel();
     lst_category = new List <CategoryMasterDataModel>();
 }