コード例 #1
0
        public void Subscribe(int userId, int establishmentId)
        {
            var user          = _context.User.Include(u => u.Subscriptions).SingleOrDefault(u => userId == u.UserId);
            var establishment = _context.Establishment.Find(establishmentId);

            if (user == null)
            {
                throw new AuthenticationException("User does not exist");
            }
            if (establishment == null)
            {
                throw new AuthenticationException("Establishment does not exist");
            }

            var userEstablishment = new UserEstablishment {
                UserId = userId, EstablishmentId = establishmentId
            };

            // check if user is already subscribed
            if (user.Subscriptions.Any(ue =>
                                       ue.UserId == userEstablishment.UserId && ue.EstablishmentId == establishment.EstablishmentId))
            {
                throw new AuthenticationException("User is already subscribed to this establishment");
            }

            user.Subscriptions.Add(userEstablishment);

            _context.User.Update(user);
            _context.SaveChanges();
        }
コード例 #2
0
        public static string GetRepresentatvieType(this UserEstablishment userEstablishment)
        {
            if (userEstablishment == null)
            {
                return(string.Empty);
            }

            switch (userEstablishment.TypeId)
            {
            case 1:
                return("Owner");

            case 2:
                return("Agent");

            case 3:
                return("Commissioner");
            }

            return(string.Empty);
        }
コード例 #3
0
 public static EstablishmentDto ToDto(this Establishment establishment, EstablishmentKPI establishmentKpi, UserEstablishment userEstablishment)
 {
     return(new EstablishmentDto
     {
         Name = establishment.Name,
         Color = establishmentKpi?.Color.Name,
         CommercialRecordNumber = establishment.CommercialRecordNumber,
         EconomicActivity = establishment.SubEconomicActivity?.ActivityName,
         Number = $"{establishment.LaborOfficeId}-{establishment.SequenceNumber}",
         OwnerIdOrSevenHundred = establishment.GetOwnerIdOrSevenHundred(),
         WaselAddress = establishment.GetWasselAddress(),
         Email = establishment.Email,
         Phone = establishment.GetPhone(),
         EstablishmentRepresentatvie = new EstablishmentRepresentatvieDto
         {
             Email = string.Empty,
             Mobile = string.Empty,
             Name = userEstablishment?.Name,
             Type = userEstablishment?.GetRepresentatvieType()
         }
     });
 }