示例#1
0
 protected override async Task <Models.User> BindUser(RegisterMusicianRequest requestBody, DateTime creationDate)
 {
     return(await Task.Run(() => new Musician()
     {
         _id = ObjectId.GenerateNewId(creationDate),
         StartDate = ValidationUtils.ValidateBornDate(requestBody.Nascimento),
         Email = ValidationUtils.ValidateEmail(requestBody.Email),
         EmailConfirmed = false,
         Address = new Address()
         {
             City = requestBody.Cidade,
             State = EnumExtensions.FromShortDisplayName <BrazilState>(requestBody.Uf),
         },
         Phone = ValidationUtils.ValidatePhoneNumber(requestBody.Telefone),
         Ip = TrackedEntity <IPAddress> .From(HttpContext.Connection.RemoteIpAddress, creationDate),
         TrackedPosition = TrackedEntity <GeoJsonPoint <GeoJson3DGeographicCoordinates> > .From(null, creationDate),
         FullName = ValidationUtils.ValidateName(requestBody.NomeCompleto),
         Password = Encryption.Encrypt(ValidationUtils.ValidatePassword(requestBody.Senha)),
         PremiumLevel = PremiumLevel.None,
         Avatar = null,
         InstrumentSkills = requestBody.Instrumentos?.DefaultIfEmpty().Where(instr => instr != null).ToDictionary(instr => EnumExtensions.FromDisplayName <Skill>(instr.Nome), el => (SkillLevel)el.NivelHabilidade).ToHashSet(),
         Works = new HashSet <Models.Work>(),
         Songs = new HashSet <Models.Song>(),
         About = requestBody.Sobre,
         Visits = 0
     }));
 }
 protected override async Task <Models.User> BindUser(RegisterContractorRequest requestBody, DateTime creationDate)
 {
     return(await Task.Run(() => new Contractor()
     {
         _id = ObjectId.GenerateNewId(creationDate),
         StartDate = ValidationUtils.ValidateStartDate(requestBody.Inauguracao),
         Email = ValidationUtils.ValidateEmail(requestBody.Email),
         EmailConfirmed = false,
         Address = new Address()
         {
             City = requestBody.Cidade,
             State = EnumExtensions.FromShortDisplayName <BrazilState>(requestBody.Uf),
             Road = requestBody.Endereco,
             Numeration = requestBody.Numero,
         },
         Phone = ValidationUtils.ValidatePhoneNumber(requestBody.Telefone),
         Ip = TrackedEntity <IPAddress> .From(HttpContext.Connection.RemoteIpAddress, creationDate),
         TrackedPosition = TrackedEntity <GeoJsonPoint <GeoJson3DGeographicCoordinates> > .From(null, creationDate),
         FullName = ValidationUtils.ValidateName(requestBody.NomeCompleto),
         Password = Encryption.Encrypt(ValidationUtils.ValidatePassword(requestBody.Senha)),
         PremiumLevel = PremiumLevel.None,
         Avatar = null,
         About = requestBody.Sobre,
         Visits = 0
     }));
 }
 protected override async Task <Contractor> BindUser(EditContractorRequest requestBody, DateTime creationDate)
 {
     return(await Task.Run(() => new Contractor()
     {
         StartDate = ValidationUtils.ValidateStartDate(requestBody.Inauguracao),
         Email = ValidationUtils.ValidateEmail(requestBody.Email),
         EmailConfirmed = false,
         Address = new Address()
         {
             City = requestBody.Cidade,
             State = EnumExtensions.FromShortDisplayName <BrazilState>(requestBody.Uf),
             Road = requestBody.Endereco,
             Numeration = requestBody.Numero,
         },
         Phone = ValidationUtils.ValidatePhoneNumber(requestBody.Telefone),
         Ip = TrackedEntity <IPAddress> .From(HttpContext.Connection.RemoteIpAddress, creationDate),
         FullName = ValidationUtils.ValidateName(requestBody.NomeCompleto),
         Password = string.IsNullOrWhiteSpace(requestBody.Senha) ? null : Encryption.Encrypt(ValidationUtils.ValidatePassword(requestBody.Senha)),
         PremiumLevel = PremiumLevel.None,
         Avatar = null,
         About = requestBody.Sobre,
     }));
 }
示例#4
0
        public void Put(LocationRequest locationRequest)
        {
            var userId = new ObjectId(this.GetCurrentUserId());

            var userCollection = MongoWrapper.Database.GetCollection <Models.User>(nameof(User));

            var userFilterBuilder = new FilterDefinitionBuilder <Models.User>();
            var userFilter        = userFilterBuilder.And(
                GeneralUtils.NotDeactivated(userFilterBuilder),
                userFilterBuilder.Eq(u => u._id, userId)
                );

            var userUpdateBuilder = new UpdateDefinitionBuilder <Models.User>();
            var userUpdate        = userUpdateBuilder.Set
                                    (
                u => u.TrackedPosition,
                TrackedEntity <GeoJsonPoint <GeoJson3DGeographicCoordinates> > .From
                (
                    new GeoJsonPoint <GeoJson3DGeographicCoordinates>
                    (
                        new GeoJson3DGeographicCoordinates(locationRequest.Latitude, locationRequest.Longitude, locationRequest.Altitude)
                    )
                )
                                    );

            // Do not await the update before returning, only log in case of error
            var updateResult = userCollection
                               .UpdateOneAsync(userFilter, userUpdate)
                               .ContinueWith
                               (
                t => Logger.LogError(t.Exception, "Error while updating user location for user {}", userId),
                TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously
                               );

            Response.StatusCode = (int)HttpStatusCode.OK;
        }
示例#5
0
 protected override async Task <Models.Musician> BindUser(EditMusicianRequest requestBody, DateTime creationDate)
 {
     return(await Task.Run(() => new Musician()
     {
         StartDate = ValidationUtils.ValidateBornDate(requestBody.Nascimento),
         Email = ValidationUtils.ValidateEmail(requestBody.Email),
         EmailConfirmed = false,
         Address = new Address()
         {
             City = requestBody.Cidade,
             State = EnumExtensions.FromShortDisplayName <BrazilState>(requestBody.Uf),
         },
         Phone = ValidationUtils.ValidatePhoneNumber(requestBody.Telefone),
         Ip = TrackedEntity <IPAddress> .From(HttpContext.Connection.RemoteIpAddress, creationDate),
         FullName = ValidationUtils.ValidateName(requestBody.NomeCompleto),
         Password = string.IsNullOrWhiteSpace(requestBody.Senha) ? null : Encryption.Encrypt(ValidationUtils.ValidatePassword(requestBody.Senha)),
         PremiumLevel = PremiumLevel.None,
         Avatar = null,
         InstrumentSkills = requestBody.Instrumentos?.DefaultIfEmpty().Where(instr => instr != null).ToDictionary(instr => EnumExtensions.FromDisplayName <Skill>(instr.Nome), el => (SkillLevel)el.NivelHabilidade).ToHashSet(),
         Works = new HashSet <Models.Work>(),
         Songs = new HashSet <Models.Song>(),
         About = requestBody.Sobre,
     }));
 }