Пример #1
0
        public async Task <IHttpActionResult> GetListAsync([FromUri] int id, [FromUri] int page = 0, [FromUri] int size = 10)
        {
            Post post = await UnitOfWork.GetPostRepository().SelectFirstOrDefaultAsync(p => p.Id == id && p.Status == Enums.PostStatus.Published)
                        ?? throw new ActionCannotBeExecutedException(ExceptionMessages.PostNotFound);

            SelectOptions <Comment> options = new SelectOptions <Comment>
            {
                OrderBy = p => p.OrderByDescending(t => t.Id),
                Take    = size,
                Skip    = page * size
            };
            StatusSpecification   specification = new StatusSpecification(Enums.CommentStatus.Active);
            ICommentRepository    repo          = UnitOfWork.GetCommentRepository();
            IEnumerable <Comment> list          = await repo.SelectAsync(specification, options);

            int resultsCount = await repo.CountAsync(specification);

            Paging paging = new Paging(page: page, count: resultsCount, size: size);

            GetListResponse response = new GetListResponse(paging)
            {
                Items = list.Select(c => new GetListResponseItem
                {
                    Id        = c.Id,
                    UserId    = c.UserId,
                    Comment   = c.Body,
                    FirstName = c.User.FirstName,
                    Image     = c.User.Image
                })
            };

            return(Ok(response));
        }
Пример #2
0
        public BugTrackingResponse <BusinessObjects.Status> Save(BusinessObjects.Status stat)
        {
            Logger.TraceMethodStart(ClassName, "Save");

            var response = new BugTrackingResponse <BusinessObjects.Status>();


            using (var db = new EntityModel.BugTrackingEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var validator = new StatusSpecification();
                        var result    = validator.Validate(stat);
                        var failures  = result.Errors;

                        response.ValidationResult = result;

                        if (result.IsValid)
                        {
                            stat.Active       = true;
                            stat.LastModified = DateTime.Now;
                            var newstat = MapperAllLevels.Map <BusinessObjects.Status, EntityModel.Status>(stat);
                            db.Status.Add(newstat);
                            db.SaveChanges();
                            transaction.Commit();
                        }

                        else
                        {
                            transaction.Rollback();
                            Logger.TraceErrorFormat("Error while Saving {0}", response.ValidationResult.Errors);
                        }

                        return(response);
                    }

                    catch (Exception ex)
                    {
                        Logger.TraceError("Exception: ", ex);
                        transaction.Rollback();
                        throw;
                    }

                    finally
                    {
                        Logger.TraceMethodEnd(ClassName, "Save");
                    }
                }
            }
        }
        public async Task <IHttpActionResult> GetListAsync([FromUri] MatchStatus?status = null, [FromUri] int page = 0, [FromUri] int size = 10)
        {
            IMatchRepository repo = UnitOfWork.GetMatchRepository();
            SelectOptions <DAL.Models.Match> options = new SelectOptions <DAL.Models.Match>
            {
                OrderBy = p => p.OrderByDescending(t => t.Id),
                Take    = size,
                Skip    = page * size
            };
            StatusSpecification            specification = new StatusSpecification(status);
            IEnumerable <DAL.Models.Match> result        = await repo.SelectAsync(specification = specification, options : options);

            int count = await repo.CountAsync(specification : specification);

            Paging paging = new Paging(count: count, page: page, size: size);

            GetListResponse response = new GetListResponse(paging)
            {
                Items = result.Select(m => new GetListResponseItem
                {
                    Id      = m.Id,
                    StartDt = m.StartDt,
                    Status  = m.Status,
                    Guest   = new GetListResponseItemTeam
                    {
                        Id       = m.GuestId,
                        City     = m.Guest.City,
                        Country  = m.Guest.County,
                        Goals    = m.Goals.Count(g => g.TeamId == m.GuestId),
                        Name     = m.Guest.Name,
                        Logotype = m.Guest.Logotype
                    },
                    Home = new GetListResponseItemTeam
                    {
                        Id       = m.HomeId,
                        City     = m.Home.City,
                        Country  = m.Home.County,
                        Goals    = m.Goals.Count(g => g.TeamId == m.HomeId),
                        Name     = m.Home.Name,
                        Logotype = m.Home.Logotype
                    }
                })
            };

            return(Ok(response));
        }
Пример #4
0
        private ISpecification <Project> BuildProjectSpecification(IEnumerable <FieldFilter> fieldFilters)
        {
            ISpecification <Project> spec = null;

            if (fieldFilters != null && fieldFilters.Any())
            {
                foreach (var fieldFilter in fieldFilters)
                {
                    ISpecification <Project> temp = null;
                    switch (fieldFilter.Field)
                    {
                    //我的项目
                    case "RelationType":
                        if (string.IsNullOrWhiteSpace(fieldFilter.Value))
                        {
                            //如果非管理员级别,增加默认的过滤条件,只能查看与自己相关的项目
                            if (!UserInfo.RightDetail.EnableViewList)
                            {
                                temp = new OrSpecification <Project>(new CreatorIdSpecification(UserInfo.UserId), new ManagerIdsSpecification(UserInfo.UserId));
                                temp = new OrSpecification <Project>(temp, new ParticipantIdsSpecification(UserInfo.UserId));
                            }
                        }
                        else
                        {
                            switch (fieldFilter.Value)
                            {
                            case "0":
                                temp = new CreatorIdSpecification(UserInfo.UserId);
                                break;

                            case "1":
                                temp = new ManagerIdsSpecification(UserInfo.UserId);
                                break;

                            case "2":
                                temp = new OrSpecification <Project>(new CreatorIdSpecification(UserInfo.UserId), new ManagerIdsSpecification(UserInfo.UserId));
                                temp = new OrSpecification <Project>(temp, new ParticipantIdsSpecification(UserInfo.UserId));
                                //temp = new OrSpecification<Project>(new ManagerIdsSpecification(UserInfo.UserId), new ParticipantIdsSpecification(UserInfo.UserId));
                                break;
                            }
                        }
                        break;

                    case "Status":
                        if (!string.IsNullOrWhiteSpace(fieldFilter.Value))
                        {
                            temp = new StatusSpecification(Int32.Parse(fieldFilter.Value));
                        }
                        break;

                    case "Type":
                        if (!string.IsNullOrWhiteSpace(fieldFilter.Value))
                        {
                            temp = new TypeSpecification(Int32.Parse(fieldFilter.Value));
                        }
                        break;

                    case "ProjectName":
                        if (!string.IsNullOrWhiteSpace(fieldFilter.Value))
                        {
                            temp = new NameSpecification(fieldFilter.Value);
                        }
                        break;

                    case "ManagerId":
                        if (!string.IsNullOrWhiteSpace(fieldFilter.Value))
                        {
                            temp = new ManagerIdsSpecification(fieldFilter.Value);
                        }
                        break;

                    case "ParticipantId":
                        if (!string.IsNullOrWhiteSpace(fieldFilter.Value))
                        {
                            temp = new ParticipantIdsSpecification(fieldFilter.Value);
                        }
                        break;

                    case "StartTime":
                    {
                        DateTime?min = null;
                        DateTime?max = null;
                        if (TryGetDateTimeSpanValue(fieldFilter.Value, ref min, ref max))
                        {
                            temp = new StartTimeSpecification(min, max);
                        }
                    }
                    break;

                    case "Deadline":
                    {
                        DateTime?min = null;
                        DateTime?max = null;
                        if (TryGetDateTimeSpanValue(fieldFilter.Value, ref min, ref max))
                        {
                            temp = new DeadlineSpecification(min, max);
                        }
                    }
                    break;
                    }
                    if (temp != null)
                    {
                        spec = spec == null ? temp : new AndSpecification <Project>(spec, temp);
                    }
                }
            }
            return(spec);
        }