public ActionResult AddItemGallary(string id) { St_ItemGallary Obj = new St_ItemGallary { ItemCode = id }; return(View(Obj)); }
public ActionResult SaveItemGalary(string id) { string ItemCode = id; bool flag = true; string fileName = ""; string userId = base.User.Identity.GetUserId(); try { var UserInfo = _unitOfWork.User.GetMyInfo(userId); string path = Path.Combine(new DirectoryInfo(string.Format(@"{0}ItemGallary\{1}", base.Server.MapPath(@"\"), ItemCode)).ToString()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (string str4 in base.Request.Files) { HttpPostedFileBase base2 = base.Request.Files[str4]; fileName = base2.FileName; if ((base2 != null) && (base2.ContentLength > 0)) { fileName = Path.GetFileName(base2.FileName); string extension = Path.GetExtension(base2.FileName); string sFileName = base2.FileName.Substring(0, base2.FileName.IndexOf('.')); sFileName = Guid.NewGuid().ToString() + extension; base2.SaveAs(Path.Combine(base.Server.MapPath(String.Format("~/ItemGallary/{0} ", ItemCode)), fileName)); St_ItemGallary objSave = new St_ItemGallary { FileName = fileName, ItemCode = ItemCode, CompanyID = UserInfo.fCompanyId }; this._unitOfWork.St_ItemGallary.Add(objSave); this._unitOfWork.Complete(); } } } catch (Exception ex) { string s = ex.Message; flag = false; } return(!flag ? base.Json(new { Message = "Error in saving file" }) : base.Json(new { Message = fileName })); }
public FileResult DownloadItemGallaryDocument(int id, string id2) { string userId = base.User.Identity.GetUserId(); ApplicationUser userByID = _unitOfWork.User.GetUserByID(userId); var UserInfo = _unitOfWork.User.GetMyInfo(userId); St_ItemGallary DocumentID = _unitOfWork.St_ItemGallary.GetFileById(UserInfo.fCompanyId, id); string path = Server.MapPath("/ItemGallary/" + id2 + "/"); byte[] fileBytes = System.IO.File.ReadAllBytes(path + DocumentID.FileName); string sfileName = DocumentID.FileName; return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, sfileName)); }
public void Add(St_ItemGallary ObjToSave) { _context.St_ItemGallarys.Add(ObjToSave); }