public ActionResult PostGoingEvent(GMN goingevent) { string userId = User.Claims.First(c => c.Type == "UserId").Value; EventsGoPeople eventsGo = new EventsGoPeople(); var gopeoplecon = _context.eventsGoPeoples.ToList(); var count = 0; foreach (var item in gopeoplecon) { if (item.UserId.Equals(userId)) { if (item.TaskId == goingevent.TaskId) { item.GMN = goingevent.Type; _context.Entry(item).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(NotFound()); } count = 1; } //_context.Entry(goingevent).State = EntityState.Modified; //try //{ // _context.SaveChangesAsync(); //} //catch (DbUpdateConcurrencyException) //{ // return NotFound(); //} } } if (count == 0) { eventsGo.UserId = userId; eventsGo.TaskId = goingevent.TaskId; eventsGo.GMN = goingevent.Type; _context.eventsGoPeoples.Add(eventsGo); _context.SaveChanges(); } return(Ok(goingevent)); }
public async Task <IActionResult> PutTodoTask(Guid Id, TodoTaskFinal todoTaskFinal) { if (Id != todoTaskFinal.Id) { return(BadRequest()); } TodoTask todoTask = _context.TodoTask.Find(todoTaskFinal.Id); if (todoTask != null) { todoTask.Task = todoTaskFinal.Task; todoTask.Date = todoTaskFinal.Date; todoTask.Description = todoTaskFinal.Description; todoTask.Place = todoTaskFinal.Place; _context.Entry(todoTask).State = EntityState.Modified; } try { string userId = User.Claims.First(c => c.Type == "UserId").Value; if (todoTaskFinal.UserId == userId) { await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!TodoTaskExists(Id)) { return(NotFound()); } else { throw; } } return(NoContent()); }