public async Task<SaveProjectResult> SaveProjectModel ()
        {
            // Project name is empty
            if (string.IsNullOrEmpty (ProjectName)) {
                return SaveProjectResult.NameIsEmpty;
            }

            // Project name is used
            var exists = await ExistProjectWithName (ProjectName);
            if (exists) {
                return SaveProjectResult.NameExists;
            }

            model.Name = ProjectName;
            model.Color = ProjectColor;

            // Save new project.
            await model.SaveAsync();

            // Create an extra model for Project / User relationship
            var userData = ServiceContainer.Resolve<AuthManager> ().User;

            var projectUserModel = new ProjectUserModel ();
            projectUserModel.Project = model;
            projectUserModel.User = new UserModel (userData);

            // Save relationship.
            await projectUserModel.SaveAsync ();

            return SaveProjectResult.SaveOk;
        }
Example #2
0
        public async Task <IActionResult> ProjectUserDelete([FromBody] ProjectUserModel model)
        {
            var result = await _projectService.GetProjectUser(model.UserId, model.ProjectId, Token);

            if (result.Success)
            {
                return(Json(await _crudService.Drop(result.Value.Id, Token, ProjectService.ProjectUserEntity)));
            }
            else
            {
                return(Json(result));
            }
        }
Example #3
0
        public async Task <ActionResult <ProjectModel> > PostProjectModel(ProjectModel projectModel)
        {
            string userId = User.Claims.First(c => c.Type == "UserID").Value;
            var    user   = await _userManager.Users.Include(x => x.UserBasic).FirstOrDefaultAsync(x => x.Id == userId);

            ProjectModel newProject = new ProjectModel()
            {
                Name      = projectModel.Name,
                AddedDate = DateTime.Now
            };



            UserBasicInfo projManager = _context.UserBasicInfo.FirstOrDefault(x => x.Id == projectModel.ProjectManager.Id);

            newProject.ProjectManager = projManager;
            UserBasicInfo projCreator = _context.UserBasicInfo.FirstOrDefault(x => x.Id == user.UserBasic.Id);

            newProject.ProjectCreator = projCreator;

            try
            {
                _context.Projects.Add(newProject);
                await _context.SaveChangesAsync();

                ProjectUserModel projMan = new ProjectUserModel()
                {
                    ProjectId = newProject.Id,
                    UserId    = projectModel.ProjectManager.Id
                };
                _context.ProjectUser.Add(projMan);

                if (projManager.Id != user.UserBasic.Id)
                {
                    ProjectUserModel projCre = new ProjectUserModel()
                    {
                        ProjectId = newProject.Id,
                        UserId    = user.UserBasic.Id
                    };
                    _context.ProjectUser.Add(projCre);
                }

                var result = await _context.SaveChangesAsync();

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <JsonResult> RemoveUserFromProject(ProjectUserModel model)
        {
            var projectId = int.Parse(model.ProjectId);
            int userId    = int.Parse(User.Identity.Name);

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

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

            // Если на задачу тречит удаляемый пользователь - останавливаем
            var runningWorktracksUsers = _dbContext.Worktracks.FirstOrDefault(x => x.Worktask.ProjectId == projectId && x.UserId == model.UserId && x.Running);

            if (runningWorktracksUsers != null)
            {
                await _hub.Value.Clients.Group(User.Identity.Name).SendAsync("getActiveTracking", false, null, false, "У вас больше нет доступа к данной задаче")
                .ConfigureAwait(false);

                runningWorktracksUsers.Running     = false;
                runningWorktracksUsers.StoppedTime = DateTime.UtcNow;

                _dbContext.Update(runningWorktracksUsers);
            }

            var linkedProjectToDelete = _dbContext.GetLinkedProjectForUser(projectId, model.UserId);

            if (linkedProjectToDelete == null)
            {
                throw new Exception("Данного пользователя не существует в проекте");
            }

            _dbContext.LinkedProjects.Remove(linkedProjectToDelete);

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

            await _dbContext.GetLinkedAcceptedProject(projectId, model.UserId, true)
            .ConfigureAwait(false);

            return(new JsonResult(new
            {
                status = HttpStatusCode.OK,
                project = linkedProject.Project
            }));
        }
Example #5
0
        public IHttpActionResult PostProject(ProjectUserModel projectUserModel)
        {
            var UserId = db.Users.FirstOrDefault(x => x.UserName == projectUserModel.userName).Id;

            if (!ModelState.IsValid)
            {
                //return BadRequest(ModelState);
            }


            projectUserModel.project.UserId = UserId;

            db.Project.Add(projectUserModel.project);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = projectUserModel.project.ProjectID }, projectUserModel.project));
        }
        public async Task<ProjectData> SaveProject (string projectName, int projectColor)
        {
            model.Name = projectName;
            model.Color = projectColor;

            // Save new project.
            await model.SaveAsync();

            // Create an extra model for Project / User relationship
            var userData = ServiceContainer.Resolve<AuthManager>().User;

            var projectUserModel = new ProjectUserModel();
            projectUserModel.Project = model;
            projectUserModel.User = new UserModel (userData);

            // Save relationship.
            await projectUserModel.SaveAsync();

            return model.Data;
        }
        public async Task <ProjectData> SaveProject(string projectName, int projectColor)
        {
            model.Name  = projectName;
            model.Color = projectColor;

            // Save new project.
            await model.SaveAsync();

            // Create an extra model for Project / User relationship
            var userData = ServiceContainer.Resolve <AuthManager>().User;

            var projectUserModel = new ProjectUserModel();

            projectUserModel.Project = model;
            projectUserModel.User    = new UserModel(userData);

            // Save relationship.
            await projectUserModel.SaveAsync();

            return(model.Data);
        }
Example #8
0
        public async Task SaveProjectModel()
        {
            // Save new project.
            await model.SaveAsync();

            // Create an extra model for Project / User relationship
            var userData = ServiceContainer.Resolve <AuthManager> ().User;
            var userId   = userData != null ? userData.Id : (Guid?)null;

            if (userId.HasValue)
            {
                var projectUserModel = new ProjectUserModel();
                projectUserModel.Project = model;
                projectUserModel.User    = new UserModel(userId.Value);
                await projectUserModel.SaveAsync();
            }

            // Update entry list.
            var timeEntryGroup = new TimeEntryGroup(timeEntryList);

            timeEntryGroup.Project   = model;
            timeEntryGroup.Workspace = workspaceModel;
            await timeEntryGroup.SaveAsync();
        }
Example #9
0
 public async Task <ActionResult <BaseResponseModelPost> > Post([FromBody] ProjectUserModel model)
 {
     return(await _projectUserService.Create(model));
 }
Example #10
0
        public Task DeleteProjectUser(ProjectUserModel model)
        {
            var url = new Uri(v8Url, String.Format("project_users/{0}", model.RemoteId.Value.ToString()));

            return(DeleteModel(url));
        }
Example #11
0
        public Task CreateProjectUser(ProjectUserModel model)
        {
            var url = new Uri(v8Url, "project_users");

            return(CreateModel(url, model));
        }