Exemplo n.º 1
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
            }));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> Add([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)
            {
                throw new Exception(TextResource.API_NoAccess);
            }

            worktask.CreatedDate = DateTime.UtcNow;

            var addedTask = await _context.AddAsync(worktask)
                            .ConfigureAwait(false);

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

            return(new JsonResult(new WorktaskAddResponse {
                worktask = worktask
            }));
        }