public ActionResult ArPhoto(IEnumerable <HttpPostedFileBase> photo, string[] photoAnnotation) { if (ModelState.IsValid) { int i = 0; int ActivityId = (int)TempData["addId"]; foreach (var fileBase in photo) { ActivityPhoto activityPhotoAdd = new ActivityPhoto(); activityPhotoAdd.ActivityId = ActivityId; if (fileBase != null && fileBase.ContentLength > 0) { activityPhotoAdd.Photo = Utility.SaveUpImage(fileBase); Utility.GenerateThumbnailImage(activityPhotoAdd.Photo, fileBase.InputStream, Server.MapPath("~/UpFile/Images"), "s", 167, 115); } activityPhotoAdd.PhotoAnnotation = photoAnnotation[i]; activityPhotoAdd.DateTime = DateTime.Now; db.ActivityPhotos.Add(activityPhotoAdd); i++; } db.SaveChanges(); return(RedirectToAction("Index")); } TempData["tab"] = 1; return(View()); }
public ActionResult DeleteConfirmed(Guid id) { ActivityPhoto activityPhoto = db.ActivityPhotos.Find(id); db.ActivityPhotos.Remove(activityPhoto); db.SaveChanges(); return(RedirectToAction("Index")); }
//<--------------------圖片上傳End----------------------> //<--------------------圖片刪除Start----------------------> // POST: Admin/ActivityPhotoes/Delete/5 public ActionResult ApDelete(int id, int pid) { ActivityPhoto activityPhoto = db.ActivityPhotos.Find(id); db.ActivityPhotos.Remove(activityPhoto); db.SaveChanges(); TempData["tab"] = 2; return(RedirectToAction("ApIndex", new { id = pid })); }
public ActionResult Edit([Bind(Include = "photoId,completeId,myActivityPhoto")] ActivityPhoto activityPhoto) { if (ModelState.IsValid) { db.Entry(activityPhoto).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(activityPhoto)); }
public ActionResult Edit([Bind(Include = "Id,ActivityId,Photo,PhotoAnnotation,DateTime")] ActivityPhoto activityPhoto) { if (ModelState.IsValid) { db.Entry(activityPhoto).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ActivityId = new SelectList(db.ActivityRecords, "Id", "Title", activityPhoto.ActivityId); return(View(activityPhoto)); }
public ActionResult Create([Bind(Include = "photoId,completeId,myActivityPhoto")] ActivityPhoto activityPhoto) { if (ModelState.IsValid) { activityPhoto.photoId = Guid.NewGuid(); db.ActivityPhotos.Add(activityPhoto); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(activityPhoto)); }
// GET: ActivityPhotos/Delete/5 public ActionResult Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ActivityPhoto activityPhoto = db.ActivityPhotos.Find(id); if (activityPhoto == null) { return(HttpNotFound()); } return(View(activityPhoto)); }
// GET: Admin/ActivityPhotoes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ActivityPhoto activityPhoto = db.ActivityPhotos.Find(id); if (activityPhoto == null) { return(HttpNotFound()); } ViewBag.ActivityId = new SelectList(db.ActivityRecords, "Id", "Title", activityPhoto.ActivityId); return(View(activityPhoto)); }
public async Task <HttpResponseMessage> ActivityImage([FromUri] int activityId) { Guard.ArgumentNotNull(activityId, nameof(activityId)); // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, "This request is not properly formatted")); } var activity = Data.Activity .All() .FirstOrDefault(t => t.Id == activityId); // Check activity existence if (activity == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, $"Cannot find activity for activity ID {activityId}")); } // Check ownership var loggedUserId = this.User.Identity.GetUserId(); if (activity.CreatorId != loggedUserId) { return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, $"Only creator {activity.CreatorId} can update the activity")); } var root = HttpContext.Current.Server.MapPath(Constants.Constants.PhotoLocation); var provider = new CustomMultipartFormDataStreamProvider(root); try { // Retrieve the form data, and save the file on server await Request.Content.ReadAsMultipartAsync(provider); // Return no content if file data equal to zero var fileSize = provider.FileData.Count; if (fileSize == 0) { return(Request.CreateResponse(HttpStatusCode.NoContent)); } foreach (var file in provider.FileData) { // Check the user uploaded file name whether valiad if (string.IsNullOrEmpty(file.Headers.ContentDisposition.FileName)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "This file name is null or empty")); } var fileName = file.LocalFileName.Split(Path.DirectorySeparatorChar).Last(); var uploadedFile = FileUploadHelper.ResizeImage(Constants.Constants.DefaultResizeSize, Constants.Constants.DefaultResizeSize, file.LocalFileName, fileName, PhotoType.ActivityImage); var activityOverView = new ActivityPhoto { AuthorId = loggedUserId, DatePosted = DateTime.Now, Name = fileName, ActivityPhotoType = ActivityPhotoType.OverView, IsSoftDelete = false, Height = uploadedFile.Height, Width = uploadedFile.Width }; activity.ActivityPhotos.Add(activityOverView); this.Data.Activity.Update(activity); this.Data.SaveChanges(); // Quit when upload succeeded return(Request.CreateResponse(HttpStatusCode.OK)); } return(Request.CreateResponse(HttpStatusCode.NoContent)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } }