public ActionResult Create(HttpPostedFileBase thumbnailFile, VideoCategorySponsor vCatSponsor) { if (thumbnailFile != null && thumbnailFile.ContentLength > 0) { string extension = Path.GetExtension(thumbnailFile.FileName); string timeUpload = DateTime.Now.ToString("yyyyMMddHHmmss"); string fileName = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + thumbnailFile.FileName; string currentDomain = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"]; string folder = "UploadedImages/VideoThumbnail"; string physicalStoragePath = System.Configuration.ConfigurationManager.AppSettings[currentDomain]; string filePath = physicalStoragePath + @"\" + folder + @"\" + fileName; using (new Impersonator("uploaduser", "", "Upload@@123")) { thumbnailFile.SaveAs(filePath); } vCatSponsor.Thumbnail = currentDomain + "/" + folder + "/" + fileName; } ModelState.Clear(); TryValidateModel(vCatSponsor); if (ModelState.IsValid) { _videoCatSponsorRepository.InsertOrUpdate(vCatSponsor); _videoCatSponsorRepository.Save(); return(RedirectToAction("Management")); } return(View(vCatSponsor)); }
public void InsertOrUpdate(VideoCategorySponsor videoCategorySponsor) { var model = _context.VideoCategorySponsors.Find(videoCategorySponsor.Id); if (videoCategorySponsor.Id == default(int)) { // New entity _context.VideoCategorySponsors.Add(videoCategorySponsor); } else { // Existing entity _context.Entry(model).State = EntityState.Detached; _context.Entry(videoCategorySponsor).State = EntityState.Modified; } }
public ActionResult Edit(HttpPostedFileBase thumbnailFile, VideoCategorySponsor vCatSponsor, string returnUrl) { string currentDomain = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"]; var physicalStoragePath = System.Configuration.ConfigurationManager.AppSettings[currentDomain]; //Thay thế file thumbnail if (thumbnailFile != null && thumbnailFile.ContentLength > 0) { //Xóa file thumbnail cũ string oldFilePath = VITV.Web.Helpers.UrlHelper.GetPhysicalPath(this, vCatSponsor.Thumbnail); using (new Impersonator("uploaduser", "", "Upload@@123")) { if (System.IO.File.Exists(oldFilePath)) { System.IO.File.Delete(oldFilePath); } } string extension = Path.GetExtension(thumbnailFile.FileName); string timeUpload = DateTime.Now.ToString("yyyyMMddHHmmss"); string fileName = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + thumbnailFile.FileName; string folder = "UploadedImages/VideoThumbnail"; string filePath = physicalStoragePath + @"\" + folder + @"\" + fileName; using (new Impersonator("uploaduser", "", "Upload@@123")) { thumbnailFile.SaveAs(filePath); } vCatSponsor.Thumbnail = currentDomain + "/" + folder + "/" + fileName; } ModelState.Clear(); TryValidateModel(vCatSponsor); if (ModelState.IsValid) { _videoCatSponsorRepository.InsertOrUpdate(vCatSponsor); _videoCatSponsorRepository.Save(); return(Json(new { success = true, id = vCatSponsor.Id })); } return(Json(new { success = false, view = this.RenderRazorViewToString("Edit", vCatSponsor) })); }
public DbPropertyEntry GetProperty <TProperty>(VideoCategorySponsor videoCategorySponsor, Expression <Func <VideoCategorySponsor, TProperty> > property) { return(_context.Entry(videoCategorySponsor).Property(property)); }
public void Load <TElement>(VideoCategorySponsor videoCategorySponsor, Expression <Func <VideoCategorySponsor, ICollection <TElement> > > includeProperty) where TElement : class { _context.VideoCategorySponsors.Attach(videoCategorySponsor); _context.Entry(videoCategorySponsor).Collection(includeProperty).Load(); }