Ejemplo n.º 1
0
        public virtual async Task <IActionResult> Create(TEntity entity)
        {
            if (ModelState.IsValid)
            {
                await repository.CreateAsync(entity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(entity));
        }
        public async Task ProcessRedeem(int userId, int organizationId)
        {
            var membership = await organizationMembershipRepository.Get().FirstOrDefaultAsync(om => om.OrganizationId == organizationId && om.UserId == userId);

            if (membership == null)
            {
                Log.Information($"ProcessRedeem: Membership not found for userId={userId}, orgId={organizationId}: Creating!");
                membership = await organizationMembershipRepository.CreateAsync(new OrganizationMembership
                {
                    OrganizationId = organizationId,
                    UserId         = userId
                });
            }
            else
            {
                Log.Information($"ProcessRedeem: Membership found for userId={userId}, orgId={organizationId}: Ignoring.");
            }
            ClearRecurringJob(userId, organizationId);
        }
        public async Task <OrganizationMembership> RedeemAsync(Guid token)
        {
            var invite = await organizationMembershipInviteRepository.Get()
                         .Include(omi => omi.Organization)
                         .Where(omi => omi.Token == token)
                         .DefaultIfEmpty(null)
                         .FirstOrDefaultAsync();

            if (invite == null)
            {
                throw new InviteNotFoundExcpetion();
            }

            if (invite.Redeemed)
            {
                throw new InviteRedeemedException();
            }

            if (invite.Expires < DateTime.Today)
            {
                throw new InviteExpiredException();
            }

            var currentUser = await currentUserRepository.GetCurrentUser();


            var membership = currentUser.OrganizationMemberships.Find(om => om.OrganizationId == invite.OrganizationId);

            if (membership == null)
            {
                membership = await organizationMembershipRepository.CreateAsync(new OrganizationMembership
                {
                    Organization = invite.Organization,
                    User         = currentUser
                });
            }

            invite.Redeemed = true;
            await organizationMembershipInviteRepository.UpdateAsync(invite.Id, invite);

            return(membership);
        }
 public async Task <T> CreateAsync(T entity)
 {
     return(await _entityRepository.CreateAsync(entity));
 }
Ejemplo n.º 5
0
        public async Task <bool> Add(AddSaveFilterViewModel model, int userId, Language language, string deviceId)
        {
            SaveFilter saveFilter = new SaveFilter();
            Guest      guest      = new Guest();
            var        user       = await _repository.FilterAsNoTracking <User>(u => u.Id == userId).FirstOrDefaultAsync();

            if (user == null)
            {
                guest = await _repository.FilterAsNoTracking <Guest>(g => g.DeviceId == deviceId).FirstOrDefaultAsync();

                if (guest == null)
                {
                    throw new Exception(_optionsBinder.Error().UserNotFound);
                }
                saveFilter.GuestId = guest.Id;
            }
            else
            {
                saveFilter.UserId = user.Id;
            }

            var filterCount = 0;

            if (string.IsNullOrEmpty(model.SaveFilterName))
            {
                throw new Exception(_optionsBinder.Error().FilterName);
            }
            if (!string.IsNullOrEmpty(model.Search))
            {
                saveFilter.Search = model.Search;
                filterCount      += 1;
            }
            if (model.AnnouncementType.HasValue)
            {
                if (saveFilter.Description == null)
                {
                    saveFilter.Description = model.AnnouncementType.ToString();
                }
                saveFilter.AnnouncementType = model.AnnouncementType;
                filterCount += 1;
            }
            if (model.AnnouncementEstateType.HasValue)
            {
                if (saveFilter.Description == null)
                {
                    saveFilter.Description = model.AnnouncementEstateType.ToString();
                }
                saveFilter.AnnouncementEstateType = model.AnnouncementEstateType;
                filterCount += 1;
            }
            if (model.AnnouncementRentType.HasValue)
            {
                saveFilter.AnnouncementRentType = model.AnnouncementRentType;
                filterCount += 1;
            }
            if (model.AnnouncementResidentialType.HasValue)
            {
                saveFilter.AnnouncementResidentialType = model.AnnouncementResidentialType;
                filterCount += 1;
            }
            if (model.LandType.HasValue)
            {
                saveFilter.LandType = model.LandType;
                filterCount        += 1;
            }
            if (model.ConstructionStatus.HasValue)
            {
                saveFilter.ConstructionStatus = model.ConstructionStatus;
                filterCount += 1;
            }
            if (model.LandCategory.HasValue)
            {
                saveFilter.LandCategory = model.LandCategory;
                filterCount            += 1;
            }
            if (model.FurnishingStatus.HasValue)
            {
                saveFilter.FurnishingStatus = model.FurnishingStatus;
                filterCount += 1;
            }
            if (model.SaleType.HasValue)
            {
                saveFilter.SaleType = model.SaleType;
                filterCount        += 1;
            }
            if (model.BuildingAge.HasValue)
            {
                saveFilter.BuildingAge = model.BuildingAge;
                filterCount           += 1;
            }
            if (model.CommercialType.HasValue)
            {
                saveFilter.CommercialType = model.CommercialType;
                filterCount += 1;
            }
            if (model.FacadeType.HasValue)
            {
                saveFilter.FacadeType = model.FacadeType;
                filterCount          += 1;
            }
            if (model.OwnerShip.HasValue)
            {
                saveFilter.OwnerShip = model.OwnerShip;
                filterCount         += 1;
            }
            if (model.SittingCount.HasValue)
            {
                saveFilter.SittingCount = model.SittingCount;
                filterCount            += 1;
            }
            if (model.CountryId.HasValue)
            {
                saveFilter.CountryId   = model.CountryId;
                saveFilter.CountryName = model.CountryName;
                filterCount           += 1;
            }
            if (model.CityId.HasValue)
            {
                saveFilter.CityId   = model.CityId;
                saveFilter.CityName = model.CityName;
                filterCount        += 1;
            }
            if (model.PriceFrom > 0 || model.PriceTo > 0)
            {
                saveFilter.PriceTo   = model.PriceTo;
                saveFilter.PriceFrom = model.PriceFrom;
                filterCount         += 1;
            }
            if (model.MinArea > 0 || model.MaxArea > 0)
            {
                saveFilter.MinArea = model.MinArea;
                saveFilter.MaxArea = model.MaxArea;
                filterCount       += 1;
            }
            if (model.MaxMeterPrice.HasValue || model.MinMeterPrice.HasValue)
            {
                saveFilter.MinMeterPrice = model.MinMeterPrice;
                saveFilter.MaxMeterPrice = model.MaxMeterPrice;
                filterCount += 1;
            }
            if (model.BathroomCount != 0 && model.BathroomCount.HasValue)
            {
                saveFilter.BathroomCount = model.BathroomCount;
                filterCount += 1;
            }
            if (model.BedroomCount != 0 && model.BedroomCount.HasValue)
            {
                saveFilter.BedroomCount = model.BedroomCount;
                filterCount            += 1;
            }
            saveFilter.SaveFilterName = model.SaveFilterName;

            if (model.Features.Count() != 0)
            {
                foreach (var item in model.Features)
                {
                    _repository.Create(new SaveFilterFeature
                    {
                        FeatureType = item,
                        SaveFilter  = saveFilter
                    });
                }
                filterCount += 1;
            }
            saveFilter.FilterCount = filterCount;

            await _repository.CreateAsync(saveFilter);

            await _repository.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 6
0
        public async Task <bool> AddGuestAsync(string deviceId, string deviceToken,
                                               OsType osType, Language language, string currencyCode)
        {
            Currency currency = _repository.Filter <Currency>(c => c.Code == currencyCode && !c.IsDeleted).FirstOrDefault();

            if (string.IsNullOrEmpty(deviceId))
            {
                throw new Exception(_optionsBinder.Error().RequiredParameters);
            }
            var guest = await _repository.Filter <Guest>(x => x.DeviceId == deviceId).FirstOrDefaultAsync();

            if (guest != null)
            {
                var otherSetting = await _repository.Filter <PersonOtherSetting>(x => x.GuestId == guest.Id).FirstOrDefaultAsync();

                if (otherSetting != null)
                {
                    otherSetting.Language = language;
                    otherSetting.AreaUnit = AreaUnit.SquareMeter;
                    _repository.Update(otherSetting);
                }
                else
                {
                    await _repository.CreateAsync(new PersonOtherSetting
                    {
                        GuestId  = guest.Id,
                        Language = language,
                        AreaUnit = AreaUnit.SquareMeter
                    });
                }
                await _repository.SaveChangesAsync();

                return(true);
            }
            else if (guest == null)
            {
                var newGuest = _repository.Create(new Guest
                {
                    DeviceId   = deviceId,
                    OsType     = osType,
                    Token      = deviceToken,
                    CurrencyId = currency.Id
                });
                foreach (SubscriptionsType variable in Enum.GetValues(typeof(SubscriptionsType)))
                {
                    if (variable == SubscriptionsType.PhoneNumberVisibility)
                    {
                        continue;
                    }
                    _repository.Create(new PersonSetting
                    {
                        GuestId           = newGuest.Id,
                        SubscriptionsType = variable
                    });
                }
                _repository.Create(new PersonOtherSetting
                {
                    GuestId  = newGuest.Id,
                    AreaUnit = AreaUnit.SquareMeter,
                    Language = language
                });
            }
            await _repository.SaveChangesAsync();

            return(true);
        }