public async Task<IHttpActionResult> PutEventPicture(int id, EventPicture eventPicture) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != eventPicture.EventPicutreNo) { return BadRequest(); } db.Entry(eventPicture).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventPictureExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public ActionResult DeleteEventPicture(int eventpictureid) { EventPicture deletepicture = eventpicturerepository.DeleteEventPicture(eventpictureid); if (deletepicture != null) { TempData["message"] = string.Format("{0} has been deleted", deletepicture.EventPictureID); } return(RedirectToAction("EventList")); }
public EventPicture DeleteEventPicture(int pictureid) { EventPicture dbEntry = context.EventPictures.Find(pictureid); if (dbEntry != null) { dbEntry.EventPictureStatus = false; context.SaveChanges(); } return(dbEntry); }
public ActionResult Create(Event _event, int theme, int hostedby, List <HttpPostedFileBase> files) { _event.themeid = theme; _event.hostedbyid = hostedby; _event.adminid = null; _event.CreationDate = DateTime.Now; if (files.First() == null || verifyFiles(files)) { try { _event.creatorid = spu.Get(x => x.username == User.Identity.Name).id; spe.create_event(_event); if (files.First() != null) { var path = ""; int i = 1; foreach (var item in files) { string name = "id" + _event.idEvent + "im" + i + Path.GetExtension(item.FileName); EventPicture image = new EventPicture(); path = Path.Combine(Server.MapPath("../Content/eventpics/"), name); item.SaveAs(path); image.eventid = _event.idEvent; image.picName = name; sep.Add(image); sep.Commit(); i++; } } return(RedirectToAction("Index")); } catch { ViewBag.Error = "error occured try again later"; return(RedirectToAction("Create")); } } else { List <University> listuniv = new List <University>(); listuniv = spun.GetAll().ToList(); ViewBag.listuniv = listuniv; List <Theme> themelist = new List <Theme>(); themelist = spt.GetAll().ToList(); ViewBag.themelist = themelist; ModelState.AddModelError(string.Empty, "check files extension or size or count only (png,jpg,jpeg,bmp) files and not mere than 4 pictures and the size of each one maximum of 4mb"); return(View(_event)); } }
public async Task<IHttpActionResult> PostEventPicture(EventPicture eventPicture) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.EventPictures.Add(eventPicture); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = eventPicture.EventPicutreNo }, eventPicture); }
public FileContentResult GetEventPictureImage(int eventid) { EventPicture pic = eventpicturerepository.EventPictures.FirstOrDefault(p => p.EventID == eventid); if (pic != null) { return(File(pic.EventPictureImageData, pic.EventPictureMimeType)); } else { return(null); } }
public void SaveEventPicture(EventPicture eventpicture) { if (eventpicture.EventPictureID == 0) { eventpicture.EventPictureStatus = true; context.EventPictures.Add(eventpicture); } else { EventPicture dbEntry = context.EventPictures.Find(eventpicture.EventPictureID); if (dbEntry != null) { dbEntry.EventPictureImageData = eventpicture.EventPictureImageData; dbEntry.EventPictureMimeType = eventpicture.EventPictureMimeType; dbEntry.EventPictureStatus = true; } } context.SaveChanges(); }
public ActionResult AddEventPicture(EventPicture picture, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image == null) { ModelState.AddModelError("", "Image cannot empty"); } if (image != null) { picture.EventPictureMimeType = image.ContentType; picture.EventPictureImageData = new byte[image.ContentLength]; image.InputStream.Read(picture.EventPictureImageData, 0, image.ContentLength); } eventpicturerepository.SaveEventPicture(picture); TempData["message"] = string.Format("{0} has been saved", picture.EventPictureID); return(RedirectToAction("EventList")); } return(View(picture)); }
public PartialViewResult _CreateEventPicture(int eventid, EventPicture picture, HttpPostedFileBase image) { eventid = 1; if (ModelState.IsValid) { if (image == null) { ModelState.AddModelError("", "Image cannot empty"); } if (image != null) { picture.EventPictureMimeType = image.ContentType; picture.EventPictureImageData = new byte[image.ContentLength]; image.InputStream.Read(picture.EventPictureImageData, 0, image.ContentLength); } picture.EventID = eventid; eventpicturerepository.SaveEventPicture(picture); TempData["message"] = string.Format("{0} has been saved", picture.EventPictureID); return(PartialView(picture)); } return(PartialView(picture)); }
public static EventPicture ToEntity(this EventPictureModel model, EventPicture destination) { return(model.MapTo(destination)); }
public void AddToEventPictures(EventPicture eventPicture) { base.AddObject("EventPictures", eventPicture); }
public static EventPicture CreateEventPicture(int eventPictureID, int eventID, int postedByUserID, bool deleted, global::System.DateTime createdDate, string createdByFullName, global::System.DateTime lastUpdatedDate, string lastUpdatedByFullName) { EventPicture eventPicture = new EventPicture(); eventPicture.EventPictureID = eventPictureID; eventPicture.EventID = eventID; eventPicture.PostedByUserID = postedByUserID; eventPicture.Deleted = deleted; eventPicture.CreatedDate = createdDate; eventPicture.CreatedByFullName = createdByFullName; eventPicture.LastUpdatedDate = lastUpdatedDate; eventPicture.LastUpdatedByFullName = lastUpdatedByFullName; return eventPicture; }
public async Task<IHttpActionResult> PostEvent() { EventDetailsDTO @eventDetail = new EventDetailsDTO(); Event @event = new Event(); List<EventPicture> @eventPictureList = new List<EventPicture>(); EventPicture @eventPicture = new EventPicture(); PatterResultType @patterResultType = new PatterResultType(); if (!Request.Content.IsMimeMultipartContent()) { //throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var folder = HostingEnvironment.MapPath(UploadPath.PATH); Utilities.CreateDirectory(folder); var provider = new CustomMultipartFormDataStreamProvider(folder); try { await Request.Content.ReadAsMultipartAsync(provider); // Show all the key-value pairs. foreach (var key in provider.FormData) { foreach (var val in provider.FormData.GetValues(key.ToString())) { switch (key.ToString()) { case "EventNo": @event.EventNo = int.Parse(val); break; case "WriteId": @event.WriteId = val; break; case "Title": @event.Title = val; break; case "Content": @event.Content = val; break; default: break; } } } db.Events.Add(@event); await db.SaveChangesAsync(); foreach (MultipartFileData file in provider.FileData) { //Trace.WriteLine("Server file name: " + file.Headers.ContentDisposition.FileName); //Trace.WriteLine("Server file path: " + file.LocalFileName); @eventPicture.EventNo = @event.EventNo; @eventPicture.PictureName = file.Headers.ContentDisposition.FileName; @eventPicture.PicturePath = file.LocalFileName; db.EventPictures.Add(@eventPicture); await db.SaveChangesAsync(); //@eventDetail.EventPictures.Add(@eventPicture); } @eventDetail.EventNo = @event.EventNo; @eventDetail.WriteId = @event.WriteId; @eventDetail.Title = @event.Title; @eventDetail.Content = @event.Content; //var picture = db.EventPictures.FindAsync(@event.EventNo); //@eventDetail.EventPictures = picture. //@eventDetail.EventPictures = //foreach (var item in @eventPicture) //{ // @eventDTO.EventPictures.Add(item); //} //@event.EventPictures = @eventPictureList; //return Request.CreateResponse(HttpStatusCode.OK, @event.ToString()); //var result = new List<ListItems>(); @patterResultType.JsonDataSet = @eventDetail.ToString(); @patterResultType.IsSuccessful = true; //return new JsonResult{ Data = result}; return Ok(@patterResultType); } catch (System.Exception e) { //return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e); return InternalServerError(e); } }
public void UpdateEventPicture(EventPicture eventPicture) { _eventPictureRepository.Update(eventPicture); }
public void InsertEventPicture(EventPicture eventPicture) { _eventPictureRepository.Insert(eventPicture); }
public List<EventPicture> GetEventPictures(Int64 EventID) { dl = new DataLayer(pConnectionString); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "[GetEventsPictures]"; cmd.Parameters.AddWithValue("@EventID", EventID); List<EventPicture> Pictures = new List<EventPicture>(); DataTable dt = dl.Execute(cmd); foreach (DataRow dr in dt.Rows) { EventPicture picture = new EventPicture { PictureID = Int64.Parse(dr["PictureID"].ToString()), PictureURL = dr["PictureURL"].ToString(), }; Pictures.Add(picture); } return Pictures; }
public static EventPictureModel ToModel(this EventPicture entity) { return(entity.MapTo <EventPicture, EventPictureModel>()); }