Пример #1
0
        public ServiceSingleResult <bool> AddWorkItem(WorkItem item)
        {
            var result = new ServiceSingleResult <bool>();

            if (item != null && item.Issue != null)
            {
                var projUserRef = _accessService.GetAccessByWorkItem(item, item.CreatorId);
                if (projUserRef == null || !Inspector.CanUserUpdateProject(projUserRef))
                {
                    result.HandleError(ErrorMessagesDict.AccessDenied);
                    return(result);
                }

                if (!Inspector.IsValidWorkItemTime(item))
                {
                    result.HandleError(ErrorMessagesDict.WrongEstimatedTimeFormat);
                    return(result);
                }

                _context.WorkItems.Add(item);
                try
                {
                    _context.SaveChanges();
                    result.TargetObject = true;
                }
                catch (Exception exc)
                {
                    result.HandleError(exc.Message);
                }
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NullInstance);
            return(result);
        }
Пример #2
0
        public ServiceSingleResult <bool> DeleteWorkItem(long itemId, string userId)
        {
            var result = new ServiceSingleResult <bool>();
            var item   = GetWorkItemById(itemId);

            if (item != null)
            {
                //check security
                var projUserRef = _accessService.GetAccessByWorkItem(item, userId);
                if (projUserRef == null || !Inspector.CanUserUpdateProject(projUserRef))
                {
                    result.HandleError(ErrorMessagesDict.AccessDenied);
                    return(result);
                }

                _context.WorkItems.Remove(item);
                try
                {
                    _context.SaveChanges();
                    result.TargetObject = true;
                }
                catch (Exception exc)
                {
                    result.HandleError(exc.Message);
                }
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NotFoundResource);
            return(result);
        }
Пример #3
0
        public ServiceSingleResult <bool> AddIssue(Issue issue)
        {
            var result = new ServiceSingleResult <bool>();

            if (issue != null && issue.Project != null)
            {
                //check user access to the project
                var projUserRef = _accessService.GetAccessByIssue(issue, issue.CreatorId);
                if (projUserRef == null || !Inspector.CanUserUpdateProject(projUserRef))
                {
                    result.HandleError(ErrorMessagesDict.AccessDenied);
                    return(result);
                }

                _context.Issues.Add(issue);
                try
                {
                    _context.SaveChanges();
                    result.TargetObject = true;
                }
                catch (Exception exc)
                {
                    result.HandleError(exc.Message);
                }
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NullInstance);
            return(result);
        }
Пример #4
0
        public ServiceSingleResult <bool> UpdateWorkItem(WorkItem item, string userId)
        {
            var result = new ServiceSingleResult <bool>();

            if (item != null)
            {
                var itemToUpdate = GetWorkItemById(item.Id);

                if (itemToUpdate != null)
                {
                    //check security
                    var projUserRef = _accessService.GetAccessByWorkItem(itemToUpdate, userId);
                    if (projUserRef == null || !Inspector.CanUserUpdateProject(projUserRef))
                    {
                        result.HandleError(ErrorMessagesDict.AccessDenied);
                        return(result);
                    }

                    if (!Inspector.IsValidWorkItemTime(item))
                    {
                        result.HandleError(ErrorMessagesDict.WrongEstimatedTimeFormat);
                        return(result);
                    }

                    _context.Entry(itemToUpdate).CurrentValues.SetValues(item);
                    try
                    {
                        _context.SaveChanges();
                        result.TargetObject = true;
                    }
                    catch (Exception exc)
                    {
                        result.HandleError(exc.Message);
                    }
                    return(result);
                }

                result.HandleError(ErrorMessagesDict.NotFoundResource);
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NullInstance);
            return(result);
        }
Пример #5
0
        public ServiceSingleResult <bool> UpdateIssue(Issue issue, string userId)
        {
            var result = new ServiceSingleResult <bool>();

            if (issue != null)
            {
                var issueToUpdate = _context.Issues
                                    .SingleOrDefault(i => i.Id == issue.Id);

                if (issueToUpdate != null)
                {
                    //check user access to the project
                    var projUserRef = _accessService.GetAccessByIssue(issueToUpdate, userId);
                    if (projUserRef == null || !Inspector.CanUserUpdateProject(projUserRef))
                    {
                        result.HandleError(ErrorMessagesDict.AccessDenied);
                        return(result);
                    }

                    _context.Entry(issueToUpdate).CurrentValues.SetValues(issue);
                    try
                    {
                        _context.SaveChanges();
                        result.TargetObject = true;
                    }
                    catch (Exception exc)
                    {
                        result.HandleError(exc.Message);
                    }
                    return(result);
                }

                result.HandleError(ErrorMessagesDict.NotFoundResource);
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NullInstance);
            return(result);
        }
Пример #6
0
        public ServiceSingleResult <bool> UpdateProject(Project project, string userId)
        {
            var result = new ServiceSingleResult <bool>();

            if (project != null)
            {
                var projectToUpdate = _context.Projects
                                      .SingleOrDefault(p => p.Id == project.Id);

                if (projectToUpdate != null)
                {
                    //check permission for editiing project info
                    var projUserRef = _accessService.GetAccessByProject(projectToUpdate.Id, userId);
                    if (projUserRef == null || !Inspector.CanUserUpdateProject(projUserRef))
                    {
                        result.HandleError(ErrorMessagesDict.AccessDenied);
                        return(result);
                    }

                    _context.Entry(projectToUpdate).CurrentValues.SetValues(project);
                    try
                    {
                        _context.SaveChanges();
                        result.TargetObject = true;
                    }
                    catch (Exception exc)
                    {
                        result.HandleError(exc.Message);
                    }
                    return(result);
                }

                result.HandleError(ErrorMessagesDict.NotFoundResource);
                return(result);
            }

            result.HandleError(ErrorMessagesDict.NullInstance);
            return(result);
        }