public async Task <ActionResult> Create([Bind(Include = "DailyNewsID,Title,FileName,Remarks")] M_DailyNawsMaster m_DailyNawsMaster) { if (ModelState.IsValid) { string FullPathWithFileName1 = null; string FolderPathForImage1 = null; string FolderPath = Server.MapPath(Resources.RSAResourcesAdmin.BannerImagesPath) + "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek; if (!string.IsNullOrEmpty(Request.Files["txtFileName"].FileName)) { FullPathWithFileName1 = FolderPath + "\\" + Request.Files["txtFileName"].FileName; FolderPathForImage1 = "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek + "\\" + Request.Files["txtFileName"].FileName; } if (RSACommonFunctions.IsFolderExist(FolderPath)) { if (!string.IsNullOrEmpty(Request.Files["txtFileName"].FileName)) { Request.Files["txtFileName"].SaveAs(FullPathWithFileName1); m_DailyNawsMaster.FileName = FolderPathForImage1; } } m_DailyNawsMaster.CreatedBy = Session["LoginUser"].ToString(); m_DailyNawsMaster.CreatedDate = DateTime.Now; m_DailyNawsMaster.ModifiedBy = Session["LoginUser"].ToString(); m_DailyNawsMaster.ModifiedDate = DateTime.Now; m_DailyNawsMaster.Active = true; db.M_DailyNawsMaster.Add(m_DailyNawsMaster); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(m_DailyNawsMaster)); }
public async Task <ActionResult> Create([Bind(Include = "NewsID,NewsType,NewsSubCategoryID,NewsHeading,SubHeading,Para1,Para2,Para3,Para4,Para5,Img1,Img2,Img3,Img4,Img5,Remarks,Location")] T_News_Masters t_News_Masters) { string FullPathWithFileName1 = null; string FullPathWithFileName2 = null; string FullPathWithFileName3 = null; string FullPathWithFileName4 = null; string FullPathWithFileName5 = null; string FolderPathForImage1 = null; string FolderPathForImage2 = null; string FolderPathForImage3 = null; string FolderPathForImage4 = null; string FolderPathForImage5 = null; string FolderPath = Server.MapPath(Resources.RSAResourcesAdmin.NewsImagesPath) + "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek; if (!string.IsNullOrEmpty(Request.Files["Img1"].FileName)) { FullPathWithFileName1 = FolderPath + "\\" + Request.Files["Img1"].FileName; FolderPathForImage1 = "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek + "\\" + Request.Files["Img1"].FileName; } if (!string.IsNullOrEmpty(Request.Files["Img2"].FileName)) { FullPathWithFileName2 = FolderPath + "\\" + Request.Files["Img2"].FileName; FolderPathForImage2 = "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek + "\\" + Request.Files["Img2"].FileName; } if (!string.IsNullOrEmpty(Request.Files["Img3"].FileName)) { FullPathWithFileName3 = FolderPath + "\\" + Request.Files["Img3"].FileName; FolderPathForImage3 = "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek + "\\" + Request.Files["Img3"].FileName; } if (!string.IsNullOrEmpty(Request.Files["Img4"].FileName)) { FullPathWithFileName4 = FolderPath + "\\" + Request.Files["Img4"].FileName; FolderPathForImage4 = "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek + "\\" + Request.Files["Img4"].FileName; } if (!string.IsNullOrEmpty(Request.Files["Img5"].FileName)) { FullPathWithFileName5 = FolderPath + "\\" + Request.Files["Img5"].FileName; FolderPathForImage5 = "\\" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.DayOfWeek + "\\" + Request.Files["Img5"].FileName; } if (RSACommonFunctions.IsFolderExist(FolderPath)) { if (!string.IsNullOrEmpty(Request.Files["Img1"].FileName)) { Request.Files["Img1"].SaveAs(FullPathWithFileName1); t_News_Masters.Img1 = FolderPathForImage1; } if (!string.IsNullOrEmpty(Request.Files["Img2"].FileName)) { Request.Files["Img2"].SaveAs(FullPathWithFileName2); t_News_Masters.Img2 = FolderPathForImage2; } if (!string.IsNullOrEmpty(Request.Files["Img3"].FileName)) { Request.Files["Img3"].SaveAs(FullPathWithFileName3); t_News_Masters.Img3 = FolderPathForImage3; } if (!string.IsNullOrEmpty(Request.Files["Img4"].FileName)) { Request.Files["Img4"].SaveAs(FullPathWithFileName4); t_News_Masters.Img4 = FolderPathForImage4; } if (!string.IsNullOrEmpty(Request.Files["Img5"].FileName)) { Request.Files["Img5"].SaveAs(FullPathWithFileName5); t_News_Masters.Img5 = FolderPathForImage5; } } if (ModelState.IsValid) { t_News_Masters.CreatedBy = Session["LoginUser"].ToString(); t_News_Masters.CreatedDate = DateTime.Now; t_News_Masters.ModifiedBy = Session["LoginUser"].ToString(); t_News_Masters.ModifiedDate = DateTime.Now; t_News_Masters.Active = true; db.T_News_Masters.Add(t_News_Masters); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.NewsSubCategoryID = new SelectList(db.M_NewsSubCategoryMasters, "NewsSubCategoryID", "SubCategory", t_News_Masters.NewsSubCategoryID); ViewBag.NewsType = new SelectList(db.M_RSAMasters, "RSAID", "TableValue", t_News_Masters.NewsType); return(View(t_News_Masters)); }