예제 #1
0
 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);
 }
예제 #2
0
 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());
        }
예제 #5
0
        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());
        }
예제 #6
0
        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());
        }
예제 #7
0
        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());
        }
예제 #8
0
        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));
        }
예제 #9
0
        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));
        }
예제 #10
0
 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));
 }
예제 #11
0
        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);
        }
예제 #12
0
 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));
 }
예제 #13
0
 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));
 }
예제 #14
0
 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);
 }
예제 #15
0
        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)));
        }
예제 #16
0
        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());
        }