public TaskGroup Save(TaskGroup taskGroup) { if (taskGroup.UserTasks != null) { try { taskGroup.UserTasks.ForEach(userTask => { _context.Entry(userTask).State = EntityState.Modified; //_context.Entry(userTask.User).State = EntityState.Detached; }); } catch (Exception ex) { _context.UserTasks.RemoveRange(taskGroup.UserTasks); throw; } } _context.TaskGroups.Add(taskGroup); if (taskGroup.TaskGroupId > 0) { _context.Entry(taskGroup).State = EntityState.Modified; } _context.SaveChanges(); return(taskGroup); }
public UserTask Save(UserTask userTask) { _context.UserTasks.Add(userTask); if (userTask.UserTaskId > 0) { _context.Entry(userTask).State = EntityState.Modified; } _context.Entry(userTask.User).State = EntityState.Modified; _context.SaveChanges(); _logger.LogInformation("Saved Task Group " + userTask.UserTaskId + " " + userTask.Name); return(userTask); }
public async Task <IActionResult> PutBuilding(int id, Building building) { if (id != building.Id) { return(BadRequest()); } _context.Entry(building).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BuildingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSession(int id, Session session) { if (id != session.Id) { return(BadRequest()); } _context.Entry(session).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SessionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUserData(int id, UserData userData) { if (id != userData.UserId) { return(BadRequest()); } _context.Entry(userData).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserDataExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDepartment(int id, Department department) { if (id != department.Id) { return(BadRequest()); } _context.Entry(department).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPermissionType(int id, PermissionType permissionType) { if (id != permissionType.Id) { return(BadRequest()); } _context.Entry(permissionType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PermissionTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PuttblUserData(int id, tblUserData tblUserData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tblUserData.ID) { return(BadRequest()); } db.Entry(tblUserData).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblUserDataExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> GetActivities([FromQuery] string id) { User user = await UserManager.FindByIdAsync(id); if (user == null) { return(NotFound("The requested user does not exist")); } await UserDataContext.Entry(user).Collection(c => c.Activities).LoadAsync(); List <SimpleUserActivity> activities = new List <SimpleUserActivity>(); foreach (var activity in user.Activities) { if (activity is CoordinatorActivity) { await UserDataContext.Entry(activity).Reference(nameof(CoordinatorActivity.Coordinator)).LoadAsync(); } activities.Add(Mapper.Map <SimpleUserActivity>(activity)); } return(new JsonResult(activities)); }
public ActionResult Edit([Bind(Include = "ID,Name,Price")] UserData userData) { if (ModelState.IsValid) { db.Entry(userData).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userData)); }
public async Task <int> UpdateFields(UserEntity customer) { //_context.UserEntityDb.Update(customer); //var ret = await _context.SaveChangesAsync(); //_context.UserEntityDb.Attach(customer); //_context.Entry(customer).State = EntityState.Modified; //var ret = await _context.SaveChangesAsync(); _context.Entry(customer).State = EntityState.Detached; _context.UserEntityDb.Attach(customer); _context.Entry(customer).Property(e => e.Name).IsModified = true; _context.Entry(customer).Property(e => e.Email).IsModified = true; var ret = await _context.SaveChangesAsync(); return(ret); }
public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,BirthDay,Job,Address")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "userID,firstName,lastName,userName,email,joined")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public User Save(User user) { _context.Users.Add(user); if (user.UserId > 0) { _context.Entry(user).State = EntityState.Modified; } _context.SaveChanges(); _logger.LogInformation("Saved Task Group " + user.UserId + " " + user.FirstName); return(user); }
public async Task <IActionResult> GetUser() { string id = User.FindFirst("id").Value; User user = await UserManager.FindByIdAsync(id); if (user == null) { return(Unauthorized()); } if (!user.PhoneNumberConfirmed) { return(new OkObjectResult(Mapper.Map <UserLoginViewModel>(user))); } EntityEntry <User> entry = UserDataContext.Entry(user); await entry.Collection(u => u.Photos).LoadAsync(); await entry.Collection(u => u.Activities).LoadAsync(); return(new OkObjectResult(Mapper.Map <UserProfileViewModel>(user))); }
async Task <IActionResult> UpdateApprovalStatus(string userId, ApprovalStatus status) { string id = User.FindFirst("id").Value; User coordinator = await UserManager.FindByIdAsync(id); if (coordinator == null) { return(Unauthorized()); } User user = await UserManager.FindByIdAsync(userId); if (user == null) { return(NotFound("The requested user was not found")); } if (user.ApprovalStatus == status) { return(Ok()); } user.ApprovalStatus = status; await UserDataContext.Entry(user).Collection(u => u.Activities).LoadAsync(); Activity activityType = status == ApprovalStatus.Approved ? Activity.AccountApproved : Activity.UpdateRequested; CoordinatorActivity activity = new CoordinatorActivity(activityType, coordinator); user.Activities.Add(activity); await UserManager.UpdateAsync(user); await UserDataContext.SaveChangesAsync(); return(Ok()); }