public object AddInstituteLogo() { try { InstituteLogoParam obj = new InstituteLogoParam(); InstituteBusiness save = new InstituteBusiness(); var result = save.SaveLogoInstitute(); return(result); } catch (Exception e) { return(new Error() { IsError = true, Message = e.Message }); } }
public object SaveLogoInstitute() { try { InstituteLogoParam obj = new InstituteLogoParam(); var data = db.Tbl_Institute_Master.OrderByDescending(r => r.InstituteId).FirstOrDefault(); Tbl_Institute_Logo_Details objinst = new Tbl_Institute_Logo_Details(); var Profile = System.Web.HttpContext.Current.Request.Files["HeaderName"]; var Sign = System.Web.HttpContext.Current.Request.Files["LogoName"]; objinst.InstituteId = data.InstituteId; var httpRequest = HttpContext.Current.Request; string UploadBaseUrl = ConfigurationManager.AppSettings["UploadBaseURL"]; string fileLogo = string.Empty; string fileBanner = string.Empty; var filePath = string.Empty; string savePath = string.Empty; var filePathBanner = string.Empty; var filePathSave = string.Empty; var Upload = obj.InstituteId; objinst.CreatedId = obj.CreatedId; objinst.CreatedOn = System.DateTime.Today.Date; objinst.ModifiedOn = System.DateTime.Today.Date; objinst.ModifiedId = null; // objinst.Status = 1; var uploaddirc = Path.Combine(HttpContext.Current.Server.MapPath("/"), "InstituteUpload" + ("\\")); if (!Directory.Exists(uploaddirc)) { DirectoryInfo di = Directory.CreateDirectory(uploaddirc); } string paths = "InstituteUpload"; for (int i = 0; i < httpRequest.Files.Count; i++) { var uploadpath = Path.Combine(HttpContext.Current.Server.MapPath("/"), paths, Upload.ToString() + ("\\")); if (!Directory.Exists(uploadpath)) { DirectoryInfo di = Directory.CreateDirectory(uploadpath); } if (i == 0 && Profile != null) { var file = httpRequest.Files[i]; var Guids = Guid.NewGuid(); filePathSave = uploadpath + Guids; filePath = filePathSave + file.FileName; savePath = uploadpath; file.SaveAs(filePath); objinst.LogoName = UploadBaseUrl + paths + ("/") + Upload.ToString() + ("/") + Guids + file.FileName; //string Logo1 = data.Logo.Replace("~/", ""); //data.Logo = Logo1; } else { var file = httpRequest.Files[i]; var GuidsBanner = Guid.NewGuid(); filePathSave = uploadpath + GuidsBanner; filePathBanner = filePathSave + file.FileName; savePath = uploadpath; file.SaveAs(filePathBanner); objinst.HeaderName = UploadBaseUrl + paths + ("/") + Upload.ToString() + ("\\") + GuidsBanner + file.FileName; //string Banner1 = data.Banner.Replace("~/", ""); //data.Banner = Banner1; } } db.Tbl_Institute_Logo_Details.Add(objinst); db.SaveChanges(); return(new Result() { IsSucess = true, ResultData = "Created Institute" }); } catch (Exception E) { return(new Error() { IsError = true, Message = E.Message }); } }