public async Task <ActionResult> EditEvent(int id, EditEventViewModel model) { if (ModelState.IsValid) { // Converting the block ClanEvent clanEvent = new ClanEvent { Id = id, Title = model.EventName, EventDateAndTime = model.EventDate, Description = model.Description, Game = model.Game, Location = model.Location, }; // Saving the model based 0n if it has a image if (model.Image == null) { await EventManager.UpdateClanEventAsync(clanEvent); } else { await EventManager.UpdateClanEventAsync(clanEvent, Bitmap.FromStream(model.Image.InputStream)); } return(RedirectToAction("Events")); } ModelState.AddModelError("Model", "You did not fill in everything"); return(View(model)); }
public async Task <ActionResult> CreateEvent(CreateEventViewModel model) { if (!ModelState.IsValid) { return(View(model)); } // Converting ClanEvent clanEvent = new ClanEvent { Title = model.EventName, EventDateAndTime = model.EventDate, Game = model.Game, Description = model.Description, Location = model.Location, }; // This will choose if i want t osave the image also if (model.Image == null) { // Adding the event to the database await EventManager.CreateClanEventAsync(clanEvent); } else { // Adding the event to the database await EventManager.CreateClanEventAsync(clanEvent, Bitmap.FromStream(model.Image.InputStream)); } return(RedirectToAction("Events")); }
/// <summary> /// Updates the event and its image with the event /// </summary> /// <param name="entity">Tyhe event that needs to be saved</param> /// <param name="image">The image that goes with that event</param> public async Task UpdateClanEventAsync(ClanEvent entity, Image image) { entity.ImageLocation = SaveEventImage(image); Context.ClanEvents.Attach(entity); Context.Entry(entity).State = System.Data.Entity.EntityState.Modified; await Context.SaveChangesAsync(); }
/// <summary> /// Creates a new event and saves the image for that event aslo /// </summary> /// <param name="entity">Tyhe event that needs to be saved</param> /// <param name="image">The image that goes with that event</param> public async Task CreateClanEventAsync(ClanEvent entity, Image image) { entity.CreatedBy = Context.Users.Find(HttpContext.Current.User.Identity.GetUserId()); entity.ImageLocation = SaveEventImage(image); Context.ClanEvents.Add(entity); await Context.SaveChangesAsync(); }
public async Task <JsonResult> FullEventDetails(int eventId) { ClanEvent clanEvent = await ClanEventManager.FindByIdAsync(eventId); // Creating the view model EventViewModel model = new EventViewModel { EventName = clanEvent.Title, EventDateAndTime = clanEvent.EventDateAndTime.ToString("dd-MM-yyy HH:mm"), Location = clanEvent.Location, Game = clanEvent.Game, CreatedBy = clanEvent.CreatedBy.UserName, ImageLocation = clanEvent.ImageLocation, Description = clanEvent.Description }; return(Json(new { model }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> EditEvent(int id) { ViewBag.ActivePage = "Events"; ClanEvent clanEvent = await EventManager.FindByIdAsync(id); // Creating the event view model EditEventViewModel model = new EditEventViewModel { EventName = clanEvent.Title, EventDate = clanEvent.EventDateAndTime, Description = clanEvent.Description, Game = clanEvent.Game, Location = clanEvent.Location, OrginalImageUrl = clanEvent.ImageLocation }; return(View(model)); }
/// <summary> /// Removes a entity from the applciation /// </summary> /// <param name="entity">the event that needs to be removed</param> public async Task DeleteClanEventAsync(ClanEvent entity) { Context.ClanEvents.Remove(entity); await Context.SaveChangesAsync(); }
/// <summary> /// Updating the event /// </summary> /// <param name="entity">the entity that has to be changed</param> public async Task UpdateClanEventAsync(ClanEvent entity) { Context.ClanEvents.Attach(entity); Context.Entry(entity).State = System.Data.Entity.EntityState.Modified; await Context.SaveChangesAsync(); }
/// <summary> /// Creates a new event /// </summary> /// <param name="entity">The data that needs to passed true</param> public async Task CreateClanEventAsync(ClanEvent entity) { entity.CreatedBy = Context.Users.Find(HttpContext.Current.User.Identity.GetUserId()); Context.ClanEvents.Add(entity); await Context.SaveChangesAsync(); }