public ActionResult Edit(int?id, string Title, string Context, HttpPostedFileBase image, tbl_post post) { if (ModelState.IsValid) { tbl_photo photo = new tbl_photo(); var selectedPost = db.tbl_post.Where(x => x.PostId == id).SingleOrDefault(); if (image != null) { if (System.IO.File.Exists(Server.MapPath(selectedPost.tbl_photo.URL))) { System.IO.File.Delete(Server.MapPath(selectedPost.tbl_photo.URL)); } string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; var imagecopy = db.tbl_photo.Add(photo); selectedPost.PhotoId = imagecopy.PhotoId; db.SaveChanges(); } selectedPost.Title = Title; selectedPost.Context = Context; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult AddService(tbl_services servis, string Name, decimal Price, string Context, HttpPostedFileBase image) { ViewBag.ServiceCategoryId = new SelectList(db.tbl_servicecategory, "ServiceCategoryId", "Name"); var picture = new tbl_photo(); if (image != null) { string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string imageExtension = Path.GetExtension(Request.Files[0].FileName); string imageWay = "/Upload/images/" + pictureName + imageExtension; Request.Files[0].SaveAs(Server.MapPath(imageWay)); picture.URL = imageWay; db.SaveChanges(); } var imageCopy = db.tbl_photo.Add(picture); servis.PhotoId = imageCopy.PhotoId; servis.Active = false; servis.Date = DateTime.Now; servis.Baxis = 0; //int providerId =Convert.ToInt32(db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name).Id); //servis.Servi db.tbl_services.Add(servis); db.SaveChanges(); db.Service_To_User.Add(new Service_To_User() { serviceId = servis.ServiceId, userId = User.Identity.GetUserId() }); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(tbl_post post, string context, string Title, HttpPostedFileBase image) { if (ModelState.IsValid) { //tbl_post post = new tbl_post(); tbl_photo photo = new tbl_photo(); post.Title = Title; post.Context = context; if (image != null) { string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; db.SaveChanges(); } var imagecopy = db.tbl_photo.Add(photo); post.PhotoId = imagecopy.PhotoId; post.Accept = false; post.Active = true; post.Views = 0; post.AuthorId = db.aspnet_Users.FirstOrDefault(x => x.UserName == User.Identity.Name).UserId; post.DateTime = DateTime.Now; db.tbl_post.Add(post); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Edit(string UserName, string bio, string fb, string ins, aspnet_Users user, HttpPostedFileBase image) { var author = db.aspnet_Users.Find(UserName); if (ModelState.IsValid) { tbl_photo photo = new tbl_photo(); if (image != null) { if (System.IO.File.Exists(Server.MapPath(author.tbl_photo.URL))) { System.IO.File.Delete(Server.MapPath(author.tbl_photo.URL)); } string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; var imagecopy = db.tbl_photo.Add(photo); author.PhotoId = imagecopy.PhotoId; db.SaveChanges(); } author.Biography = bio; author.Facebook = fb; author.Instagram = ins; db.SaveChanges(); } return(View()); }
public ActionResult Create([Bind(Include = "ServiceCategoryId,Name,Description,PhotoId")] tbl_servicecategory tbl_servicecategory, HttpPostedFileBase image) { if (ModelState.IsValid) { var picture = new tbl_photo(); if (image != null) { string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string imageExtension = Path.GetExtension(Request.Files[0].FileName); string imageWay = "/Upload/images/" + pictureName + imageExtension; Request.Files[0].SaveAs(Server.MapPath(imageWay)); picture.URL = imageWay; db.SaveChanges(); } var imageCopy = db.tbl_photo.Add(picture); tbl_servicecategory.PhotoId = imageCopy.PhotoId; db.tbl_servicecategory.Add(tbl_servicecategory); db.SaveChanges(); return(RedirectToAction("Index", "AdminCategory")); } return(RedirectToAction("Index", "AdminCategory")); }
public ActionResult Create(tbl_book book, string Name, int Page, string Context, HttpPostedFileBase pdf, HttpPostedFileBase image) { if (ModelState.IsValid) { //tbl_book book = new tbl_book(); tbl_photo photo = new tbl_photo(); book.Name = Name; book.Page = Page; book.Context = Context; if (pdf != null && pdf.ContentLength > 0) { string bookName = Guid.NewGuid().ToString().Replace("-", ""); string bookExtension = Path.GetExtension(Request.Files[0].FileName); string bookWay = "/Upload/book/" + bookName + bookExtension; Request.Files[0].SaveAs(Server.MapPath(bookWay)); book.Fileurl = bookWay; db.SaveChanges(); } if (image != null) { string imageName = Guid.NewGuid().ToString().Replace("-", ""); string imageExtension = Path.GetExtension(Request.Files[0].FileName); string imageWay = "/Upload/book/" + imageName + imageExtension; Request.Files[0].SaveAs(Server.MapPath(imageWay)); photo.URL = imageWay; var copyImage = db.tbl_photo.Add(photo); book.PhotoId = copyImage.PhotoId; } db.tbl_book.Add(book); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Edit(tbl_book book, int?writerId, int id, string Name, int?Page, string Context, HttpPostedFileBase pdf, HttpPostedFileBase image) { tbl_photo photo = new tbl_photo(); var selectedBook = db.tbl_book.SingleOrDefault(x => x.BookId == id); var writer = db.tbl_Writer.FirstOrDefault(x => x.WriterId == writerId).WriterId; selectedBook.tbl_Writer.WriterId = writer; if (image != null) { if (System.IO.File.Exists(Server.MapPath(selectedBook.tbl_photo.URL))) { System.IO.File.Delete(Server.MapPath(selectedBook.tbl_photo.URL)); } string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; var imagecopy = db.tbl_photo.Add(photo); selectedBook.PhotoId = imagecopy.PhotoId; db.SaveChanges(); } if (pdf != null) { if (System.IO.File.Exists(Server.MapPath(selectedBook.Fileurl))) { System.IO.File.Delete(Server.MapPath(selectedBook.Fileurl)); } string fileName = Guid.NewGuid().ToString().Replace("-", ""); string fileExtension = Path.GetExtension(Request.Files[0].FileName); string fileWay = "/Upload/book/" + fileName + fileExtension; Request.Files[0].SaveAs(Server.MapPath(fileWay)); selectedBook.Fileurl = fileWay; db.SaveChanges(); } selectedBook.Name = Name; selectedBook.Page = Page; selectedBook.Context = Context; db.Entry(book).State = EntityState.Detached; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(tbl_category cate, string name, HttpPostedFileBase image) { if (ModelState.IsValid) { tbl_category category = new tbl_category(); category.Name = name; tbl_photo photo = new tbl_photo(); if (image != null) { string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; db.SaveChanges(); } var imagecopy = db.tbl_photo.Add(photo); cate.PhotoId = imagecopy.PhotoId; db.tbl_category.Add(cate); db.SaveChanges(); } return(RedirectToAction("Index")); }