Beispiel #1
0
 public BadgeViewModel(Badge badge)
 {
     if (badge != null)
     {
         Description = badge.Description;
         GroupId = badge.GroupId;
         Id = badge.Id;
         Image = ImageService.GetImageUrl<Badge>(badge.Image);
         IsAcquired = badge.IsAcquired;
         Title = badge.Title;
         if (badge.Type.HasValue)
             Type = (BadgeType)badge.Type.Value;
         UserId = badge.UserId;
         Value = badge.Value;
         AcquireDate = badge.AcquireDate;
     }
 }
Beispiel #2
0
        public virtual Badge AwardGroup(string groupUrl)
        {
            var group = GroupService.GetGroupByLabelOrId(groupUrl);
            if (group == null)
                throw new BusinessLogicException("Группа не найдена");

            var badge = new Badge
            {
                Description = Description,
                GroupId = group.Id,
                Image = Image,
                IsAcquired = IsAcquired,
                Title = Title,
                Value = Value
            };

            if (Type.HasValue)
                badge.Type = (int)Type.Value;

            if (IsAcquired)
                badge.AcquireDate = DateTime.Now;

            DataService.PerThread.BadgeSet.AddObject(badge);
            DataService.PerThread.SaveChanges();

            return badge;
        }
Beispiel #3
0
        public virtual Badge AwardUser(Guid userId)
        {
            var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(x => x.Id == userId);
            if (user == null)
                throw new BusinessLogicException("Пользователь не найден");

            Badge badge = null;

            if (Type.HasValue)
                badge = user.Badges.SingleOrDefault(x => x.Type == (int)Type.Value);

            if (badge != null)
            {
                badge.Value = badge.Value ?? 1;
                badge.Value++;
            }
            else
            {
                badge = new Badge();
                DataService.PerThread.BadgeSet.AddObject(badge);
            }

            badge.Description = Description;
            badge.Image = Image;
            badge.IsAcquired = IsAcquired;
            badge.Title = Title;
            badge.UserId = userId;

            if (Type.HasValue)
                badge.Type = (int)Type.Value;

            if (IsAcquired)
                badge.AcquireDate = DateTime.Now;

            DataService.PerThread.SaveChanges();

            return badge;
        }