コード例 #1
0
        public async Task <JsonResult> Accept([FromBody] InviteAcceptModel model)
        {
            int projectId = model.projectId;
            int userId    = int.Parse(User.Identity.Name);

            // Проверяем, что есть доступ
            var linkedProject = _dbContext.GetLinkedProjectForUser(projectId, userId);

            if (linkedProject == null)
            {
                throw new Exception(TextResource.API_YouAreNotInvited);
            }

            if (linkedProject.Accepted)
            {
                throw new Exception(TextResource.API_InviteAccepted);
            }

            linkedProject.Accepted = true;

            _dbContext.Update(linkedProject);

            await _dbContext.SaveChangesAsync()
            .ConfigureAwait(false);

            return(new JsonResult(new ProjectAcceptResponse
            {
                project = linkedProject.Project
            }));
        }
コード例 #2
0
        public async Task <JsonResult> Update([FromBody] WorktaskUpdateModel model)
        {
            var worktask = model.worktask;

            int projectId = worktask.ProjectId;
            int userId    = int.Parse(User.Identity.Name);

            // Проверяем доступ
            var linkedProject = await _context.GetLinkedAcceptedProject(projectId, userId)
                                .ConfigureAwait(false);

            if (linkedProject == null || linkedProject.RoleId == 1)
            {
                throw new Exception(TextResource.API_NoAccess);
            }

            var dbWorkTask = await _context.Worktasks.FirstOrDefaultAsync(x => x.Id == worktask.Id)
                             .ConfigureAwait(false);

            dbWorkTask.Title       = worktask.Title;
            dbWorkTask.Description = worktask.Description;
            dbWorkTask.Duration    = worktask.Duration;
            dbWorkTask.StateId     = worktask.StateId;

            _context.Update(dbWorkTask);

            await _context.SaveChangesAsync()
            .ConfigureAwait(false);

            return(new JsonResult(new WorktaskUpdateResponse {
                worktask = worktask
            }));
        }
コード例 #3
0
        public async Task <JsonResult> Update([FromBody] UpdateStateModel model)
        {
            var dbWorkTask = await _context.Worktasks.FirstOrDefaultAsync(x => x.Id == model.TaskId)
                             .ConfigureAwait(false);

            if (dbWorkTask == null)
            {
                throw new Exception(TextResource.API_NotExistWorktaskId);
            }

            var stateExist = await _context.States.AnyAsync(x => x.Id == model.StateId)
                             .ConfigureAwait(false);

            if (!stateExist)
            {
                throw new Exception(TextResource.API_NotExistStateId);
            }

            int projectId = dbWorkTask.ProjectId;
            int userId    = int.Parse(User.Identity.Name);

            var linkedProject = _context.GetLinkedAcceptedProject(projectId, userId);

            if (linkedProject == null)
            {
                throw new Exception(TextResource.API_NoAccess);
            }

            // Если на задачу кто-то тречит - заставить их прекратить
            var runningWorktracks = _context.Worktracks.Where(x => x.WorktaskId == dbWorkTask.Id && x.Running);

            if (model.StateId == 6 && runningWorktracks.Any())
            {
                var tracks = runningWorktracks.ToList();
                var users  = tracks.Select(x => x.UserId);

                foreach (var userName in users)
                {
                    await _hub.Value.Clients.Group(userName.ToString()).SendAsync("getActiveTracking", false, null, false, TextResource.API_TrackingTaskClosed)
                    .ConfigureAwait(false);
                }

                var now = DateTime.UtcNow;
                tracks.ForEach(x =>
                {
                    x.Running     = false;
                    x.StoppedTime = now;
                });

                _context.UpdateRange(tracks);
            }

            dbWorkTask.StateId = ( byte )model.StateId;

            _context.Update(dbWorkTask);

            await _context.SaveChangesAsync(true)
            .ConfigureAwait(false);

            return(new JsonResult(new OkResponse
            {
                message = "Вы успешно изменили состояние задачи"
            }));
        }
コード例 #4
0
        public async Task <JsonResult> Update(MyPageModel model)
        {
            var dbUser = await _dbContext.GetUserAsync(User.Identity.Name, true)
                         .ConfigureAwait(false);

            var passwordChanged = !string.IsNullOrEmpty(model.Pass);

            if (passwordChanged)
            {
                var password = PasswordHelpers.EncryptPassword(model.CurrentPass, dbUser.Pass.Salt);
                if (!PasswordHelpers.SlowEquals(password, dbUser.Pass.Password))
                {
                    throw new Exception(TextResource.API_NoAccess);
                }

                var salt = PasswordHelpers.GenerateSalt();
                var hash = PasswordHelpers.EncryptPassword(model.Pass, salt);
                dbUser.Pass.Password = hash;
                dbUser.Pass.Salt     = salt;
            }

            var IV         = dbUser.IV;
            var firstName  = PasswordHelpers.EncryptData(model.FirstName, IV);
            var surName    = PasswordHelpers.EncryptData(model.Surname, IV);
            var email      = PasswordHelpers.EncryptData(model.Email, IV);
            var middleName = string.IsNullOrEmpty(model.MiddleName) ? null : PasswordHelpers.EncryptData(model.MiddleName, IV);
            var birthdate  = string.IsNullOrEmpty(model.BirthDate) ? null : PasswordHelpers.EncryptData(model.BirthDate, IV);
            var city       = string.IsNullOrEmpty(model.City) ? null : PasswordHelpers.EncryptData(model.City, IV);

            dbUser.FirstName  = firstName;
            dbUser.Surname    = surName;
            dbUser.MiddleName = middleName;
            dbUser.City       = city;
            dbUser.Email      = email;
            dbUser.BirthDate  = birthdate;

            _dbContext.Update(dbUser);

            await _dbContext.SaveChangesAsync()
            .ConfigureAwait(false);

            var user = new
            {
                dbUser.Login,
                FirstName  = model.FirstName,
                Surname    = model.Surname,
                MiddleName = model.MiddleName,
                City       = model.City,
                Email      = model.Email,
                BirthDate  = model.BirthDate
            };

            await _dbContext.GetUserAsync(User.Identity.Name, true)
            .ConfigureAwait(false);

            return(new JsonResult(new
            {
                status = HttpStatusCode.OK,
                newUser = user,
                passwordChanged = passwordChanged
            }, _jsonOptions));
        }