public async Task <IActionResult> CreateEvent(NewEventItem item) { //Check to make sure the correct item model was passed in if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Validate user if (await _userManager.GetUserAsync(User) == null) { return(Unauthorized()); } //attempt to add event var successful = await _eventItemService.AddEventAsync(item, await _userManager.GetUserAsync(User)); //check if the variable successfull is an event item if (!(successful is EventItem)) { return(BadRequest(new { error = "Could not edit item." })); } //all went well so we are returning the new guid return(Json(successful.Id.ToString())); }
public async Task <IActionResult> EditItem(Guid id, NewEventItem item) { //Check to make sure the correct item model was passed in if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Validate user var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Unauthorized()); } //attempts to grab specified event var successful = await _eventItemService.EditEventAsync(id, item, currentUser); //return Error if (!successful) { return(BadRequest(new { error = "Could not edit item." })); } //return Success return(Ok()); }
public async Task <bool> EditEventAsync(Guid id, NewEventItem newItem, ApplicationUser user) { var entity = await _context.Events .Where(x => x.Id == id && x.HostUUID == user.Id) .SingleOrDefaultAsync(); if (entity == null) { return(false); } entity.EventName = newItem.Name; entity.EventDescription = newItem.Description; entity.EventTime = newItem.EventTime; _context.Events.Update(entity); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
public async Task <EventItem> AddEventAsync(NewEventItem newItem, ApplicationUser user) { var entity = new EventItem { Id = Guid.NewGuid(), HostUUID = user.Id, EventName = newItem.Name, EventDescription = newItem.Description, EventTime = newItem.EventTime, EventCreated = DateTimeOffset.Now.DateTime, IsDeleted = false }; _context.Events.Add(entity); var saveResult = await _context.SaveChangesAsync(); if (saveResult == 1) { return(entity); } return(null); }