Example #1
0
 public Response <List <Guid> > GetRace(Guid campaighnId)
 {
     return(new Response <List <Guid> >(
                _campaighnRaceContext.GetList()
                .List()
                .Where(w => w.CampaighnId == campaighnId)
                .Select(s => s.SubraceId)
                .ToList()
                ));
 }
Example #2
0
 public Response <List <RaceListModel> > GetRaceList()
 {
     return(new Response <List <RaceListModel> >
     {
         ErrorCode = (int)ErrorEnum.Ok,
         ErrorMessage = "",
         Value = _raceContext.GetList().List().
                 Select(s => new RaceListModel {
             Id = s.Id, Name = s.Name, Description = s.Description
         })
                 .OrderBy(o => o.Name)
                 .ToList()
     });
 }
Example #3
0
 public Response <List <AttributeListModel> > GetAttributeList(Guid?attributeTypeId)
 {
     return
         (new Response <List <AttributeListModel> >(
              _dictionaryAttrContext.GetList()
              .List()
              .Where(w => w.AttributeTypeId.Equals(attributeTypeId))
              .Select(
                  s =>
                  new AttributeListModel
     {
         Id = s.Id,
         Name = s.Name
     })
              .OrderBy(o => o.Name)
              .ToList()));
 }
Example #4
0
        public static List <AttributeLinkListModel> GetAttributes <T>(this IEntityDb <T> ownerContext,
                                                                      Guid ownerId) where T : class, IAttributeableEntity
        {
            var contextAttributeGroup     = (IEntityDb <AttributeGroup>)Resolver.Resolve <IEntityDb <AttributeGroup> >();
            var contextAttributeGroupData =
                (IEntityDb <AttributeGroupData>)Resolver.Resolve <IEntityDb <AttributeGroupData> >();
            var contextAttribute =
                (IEntityDb <DictionaryAttribute>)Resolver.Resolve <IEntityDb <DictionaryAttribute> >();

            contextAttributeGroup.SetSession(ownerContext.GetSession());
            contextAttributeGroupData.SetSession(ownerContext.GetSession());
            contextAttribute.SetSession(ownerContext.GetSession());


            var attrGroupQuery = contextAttributeGroup.GetList().List().Where(ww => ownerContext.GetList()
                                                                              .List()
                                                                              .Where(w => w.OwnerId.Equals(ownerId))
                                                                              .Select(s => s.AttributeGroupId).Contains(ww.Id));


            var groupData =
                contextAttributeGroupData.GetList().List()
                .Join(contextAttribute.GetList().List(),
                      agd => agd.AttributeId,
                      att => att.Id,
                      (agd, att) => new { Group = agd, Atr = att })
                .Where(w => attrGroupQuery.Select(s => s.Id).Contains(w.Group.AttributeGroupId))
                .ToList();


            var attrGroup = attrGroupQuery.ToList();

            var answer = attrGroup.Select(s => new AttributeLinkListModel
            {
                Id    = s.Id,
                Count = s.AllowSelectCount
            }).ToList();

            foreach (var elem in answer)
            {
                elem.Attributes =
                    groupData.Where(w => w.Group.AttributeGroupId.Equals(elem.Id))
                    .Select(s => new AttributeLinkModel
                {
                    Id               = s.Group.AttributeId,
                    Value            = ConvertToType(s.Atr.Type, s.Group.Value),
                    Label            = s.Atr.Name,
                    Type             = s.Atr.Type,
                    AllowSelectCount = null,
                    ListValues       = null,
                    ListApi          = null,
                    ListApiParams    = null
                })
                    .ToList();
            }

            return(answer);
        }
Example #5
0
 public Response <List <SubraceListModel> > GetSubraceList()
 {
     return(new Response <List <SubraceListModel> >
     {
         ErrorCode = (int)ErrorEnum.Ok,
         ErrorMessage = "",
         Value = (from subrace in _subraceContext.GetList().List()
                  join race in _raceContext.GetList().List() on subrace.RaceId equals race.Id
                  orderby race.Name, subrace.Name
                  select new SubraceListModel
         {
             Id = subrace.Id,
             Name = subrace.Name,
             Description = subrace.Description,
             RaceId = race.Id,
             RaceName = race.Name
         }
                  ).ToList()
     });
 }
Example #6
0
 public Response <List <CampaighnListAnswer> > GetList(string userKey)
 {
     return
         (new Response <List <CampaighnListAnswer> >(
              _campaighnContext.GetList().List().Select(s => new CampaighnListAnswer
     {
         Name = s.Name,
         Id = s.Id,
         StartLevel = s.StartLevel
     }).ToList()));
 }
Example #7
0
        public Response <List <AttributeTypeListModel> > GetTypesList()
        {
            var originalList = _dictionaryAttrTypeContext.GetList().List().ToList();

            return(new Response <List <AttributeTypeListModel> >
                   (
                       originalList.Where(w => w.RootId.Equals(null)).Select(s => new AttributeTypeListModel
            {
                Id = s.Id,
                Name = s.Name,
                RootId = s.RootId,
                Nodes = AddToAnswer(originalList, s.Id)
            })
                       .OrderBy(o => o.Name)
                       .ToList()
                   ));
        }
Example #8
0
        public Response <List <ItemTypeListModel> > ItemTypeList()
        {
            var originalList = _itemTypeContext.GetList().List().ToList();

            return(new Response <List <ItemTypeListModel> >
            {
                ErrorCode = (int)ErrorEnum.Ok,
                ErrorMessage = "",
                Value = originalList.Where(w => w.RootId.Equals(null)).Select(s => new ItemTypeListModel
                {
                    Id = s.Id,
                    Name = s.Name,
                    Description = s.Description,
                    Plural = s.Plural,
                    RootId = s.RootId,
                    Nodes = AddToAnswer(originalList, s.Id)
                }).ToList()
            });
        }
Example #9
0
        public static void SaveAttributes <T>(this List <AttributeLinkListModel> attributeModel,
                                              Guid ownerId,
                                              IEntityDb <T> ownerContext) where T : class, IAttributeableEntity
        {
            var contextAttributeGroup     = (IEntityDb <AttributeGroup>)Resolver.Resolve <IEntityDb <AttributeGroup> >();
            var contextAttributeGroupData =
                (IEntityDb <AttributeGroupData>)Resolver.Resolve <IEntityDb <AttributeGroupData> >();

            contextAttributeGroup.SetSession(ownerContext.GetSession());
            contextAttributeGroupData.SetSession(ownerContext.GetSession());


            var deletedLinks =
                ownerContext.GetList()
                .List()
                .Where(
                    w =>
                    w.OwnerId.Equals(ownerId) &&
                    !attributeModel.Where(ww => !ww.Id.Equals(null))
                    .Select(ss => ss.Id)
                    .Contains(w.AttributeGroupId));

            var dataAttrIds = contextAttributeGroupData.GetList().List()
                              .Where(ww => attributeModel.Where(w => !w.Id.Equals(null)).Select(s => s.Id).Contains(ww.AttributeGroupId))
                              .Select(ss => new { ss.AttributeGroupId, ss.AttributeId, ss.Id }).ToList();

            foreach (var deletedLink in deletedLinks)
            {
                ownerContext.Delete(deletedLink);
            }

            foreach (var attributeElement in attributeModel)
            {
                var groupId = attributeElement.Id ?? Guid.NewGuid();

                if (attributeElement.Id.Equals(null))
                {
                    contextAttributeGroup.Upsert(new AttributeGroup
                    {
                        Id = groupId,
                        AllowSelectCount = attributeElement.Count
                    });

                    var constructor = typeof(T).GetConstructor(Type.EmptyTypes);
                    if (constructor == null)
                    {
                        throw new Exception("Не найден конструктор");
                    }

                    var newLink = (IAttributeableEntity)constructor.Invoke(new object[] { });
                    newLink.OwnerId          = ownerId;
                    newLink.AttributeGroupId = groupId;
                    newLink.Id = Guid.NewGuid();
                    ownerContext.Upsert((T)newLink);
                }
                else
                {
                    var deletingListGroupData =
                        contextAttributeGroupData.GetList()
                        .List()
                        .Where(
                            w =>
                            w.AttributeGroupId.Equals(groupId) &&
                            !attributeElement.Attributes.Select(s => s.Id).Contains(w.AttributeId)).ToList();
                    foreach (var deletedElement in deletingListGroupData)
                    {
                        contextAttributeGroupData.Delete(deletedElement);
                    }
                }

                var upsertElementGroupData =
                    attributeElement.Attributes.Select(
                        s =>
                        new AttributeGroupData
                {
                    Id =
                        dataAttrIds.FirstOrDefault(
                            f => f.AttributeGroupId.Equals(groupId) && f.AttributeId.Equals(s.Id))?.Id ??
                        Guid.NewGuid(),
                    AttributeId      = s.Id,
                    AttributeGroupId = groupId,
                    Value            = s.Value?.ToString() ?? ""
                });

                foreach (var upsertElement in upsertElementGroupData)
                {
                    contextAttributeGroupData.Upsert(upsertElement);
                }
            }
        }