예제 #1
0
        public async Task <IHttpActionResult> Update([FromBody] UsuarioViewModel usuario)
        {
            using (var context = new RedContext())
            {
                var ExistUsuario = await context.Usuarios.FirstOrDefaultAsync(b => b.Id == usuario.Id);

                if (ExistUsuario == null)
                {
                    return(NotFound());
                }

                ExistUsuario.Address      = usuario.Address;
                ExistUsuario.CityId       = usuario.CityId;
                ExistUsuario.DepartmentId = usuario.DepartmentId;
                ExistUsuario.CountryId    = usuario.CountryId;
                ExistUsuario.FirstName    = usuario.FirstName;
                ExistUsuario.Genero       = usuario.Genero;
                ExistUsuario.LastName     = usuario.LastName;
                ExistUsuario.Phone        = usuario.Phone;
                ExistUsuario.Photo        = usuario.Photo;
                ExistUsuario.UserName     = usuario.UserName;
                ExistUsuario.Password     = usuario.Password;

                await context.SaveChangesAsync();

                return(Ok(new UsuarioViewModel(ExistUsuario)));
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> Save([FromBody] DepartmentViewModel department)
        {
            using (var context = new RedContext())
            {
                var newDepartment = context.Departments.Add(new Department
                {
                    CountryId = department.CountryId,
                    Name      = department.DepartmentName
                });

                await context.SaveChangesAsync();

                return(Ok(new DepartmentViewModel(newDepartment)));
            }
        }
        public async Task <IHttpActionResult> Save([FromBody] CountryViewModel country)
        {
            using (var context = new RedContext())
            {
                var newCountry = context.Countries.Add(new Country
                {
                    Id   = country.CountryId,
                    Name = country.CountryName
                });

                await context.SaveChangesAsync();

                return(Ok(new CountryViewModel(newCountry)));
            }
        }
        public async Task <IHttpActionResult> Delete(int id)
        {
            using (var context = new RedContext())
            {
                var votingplace = await context.VotingPlaces.FirstOrDefaultAsync(r => r.Id == id);

                if (votingplace == null)
                {
                    return(NotFound());
                }

                context.VotingPlaces.Remove(votingplace);
                await context.SaveChangesAsync();
            }
            return(Ok());
        }
예제 #5
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            using (var context = new RedContext())
            {
                var department = await context.Departments.FirstOrDefaultAsync(r => r.Id == id);

                if (department == null)
                {
                    return(NotFound());
                }

                context.Departments.Remove(department);
                await context.SaveChangesAsync();
            }
            return(Ok());
        }
예제 #6
0
        public async Task <IHttpActionResult> Save([FromBody] CityViewModel city)
        {
            using (var context = new RedContext())
            {
                var newCity = context.Cities.Add(new City
                {
                    CountryId    = city.CountryId,
                    DepartmentId = city.DepartmentId,
                    Name         = city.CityName
                });

                await context.SaveChangesAsync();

                return(Ok(new CityViewModel(newCity)));
            }
        }
        public async Task <IHttpActionResult> Save([FromBody] CommuneViewModel commune)
        {
            using (var context = new RedContext())
            {
                var newCommune = context.Communes.Add(new Commune
                {
                    CommuneId    = commune.CommuneId,
                    Name         = commune.Name,
                    CountryId    = commune.CountryId,
                    DepartmentId = commune.DepartmentId,
                    CityId       = commune.CityId
                });

                await context.SaveChangesAsync();

                return(Ok(new CommuneViewModel(newCommune)));
            }
        }
        public async Task <IHttpActionResult> Update([FromBody] CountryViewModel country)
        {
            using (var context = new RedContext())
            {
                var Existcountry = await context.Countries.FirstOrDefaultAsync(b => b.Id == country.CountryId);

                if (Existcountry == null)
                {
                    return(NotFound());
                }

                Existcountry.Name = country.CountryName;

                await context.SaveChangesAsync();

                return(Ok(new CountryViewModel(Existcountry)));
            }
        }
        public async Task <IHttpActionResult> Save([FromBody] VotingPlaceViewModel votingplace)
        {
            using (var context = new RedContext())
            {
                var newVotingPlace = context.VotingPlaces.Add(new VotingPlace
                {
                    Id           = votingplace.VotingPlaceId,
                    Name         = votingplace.Name,
                    CountryId    = votingplace.CountryId,
                    DepartmentId = votingplace.DepartmentId,
                    CityId       = votingplace.CityId,
                    Code         = votingplace.Code
                });

                await context.SaveChangesAsync();

                return(Ok(new VotingPlaceViewModel(newVotingPlace)));
            }
        }
예제 #10
0
        public async Task <IHttpActionResult> Update([FromBody] DepartmentViewModel department)
        {
            using (var context = new RedContext())
            {
                var ExistDepartment = await context.Departments.FirstOrDefaultAsync(b => b.Id == department.DepartmentId);

                if (ExistDepartment == null)
                {
                    return(NotFound());
                }

                ExistDepartment.CountryId = department.CountryId;
                ExistDepartment.Name      = department.DepartmentName;

                await context.SaveChangesAsync();

                return(Ok(new DepartmentViewModel(ExistDepartment)));
            }
        }
예제 #11
0
        public async Task <IHttpActionResult> Update([FromBody] CommuneViewModel commune)
        {
            using (var context = new RedContext())
            {
                var ExistCommune = await context.Communes.FirstOrDefaultAsync(b => b.CommuneId == commune.CommuneId);

                if (ExistCommune == null)
                {
                    return(NotFound());
                }

                ExistCommune.Name         = commune.Name;
                ExistCommune.CountryId    = commune.CountryId;
                ExistCommune.DepartmentId = commune.DepartmentId;
                ExistCommune.CityId       = commune.CityId;

                await context.SaveChangesAsync();

                return(Ok(new CommuneViewModel(ExistCommune)));
            }
        }
        public async Task <IHttpActionResult> Update([FromBody] VotingPlaceViewModel votingplace)
        {
            using (var context = new RedContext())
            {
                var ExistVotingPlace = await context.VotingPlaces.FirstOrDefaultAsync(b => b.Id == votingplace.VotingPlaceId);

                if (ExistVotingPlace == null)
                {
                    return(NotFound());
                }

                ExistVotingPlace.Name         = votingplace.Name;
                ExistVotingPlace.CountryId    = votingplace.CountryId;
                ExistVotingPlace.DepartmentId = votingplace.DepartmentId;
                ExistVotingPlace.CityId       = votingplace.CityId;
                ExistVotingPlace.Code         = votingplace.Code;

                await context.SaveChangesAsync();

                return(Ok(new VotingPlaceViewModel(ExistVotingPlace)));
            }
        }
예제 #13
0
        public async Task <IHttpActionResult> Save([FromBody] UsuarioViewModel usuario)
        {
            using (var context = new RedContext())
            {
                var newUsuario = context.Usuarios.Add(new User
                {
                    Id           = usuario.Id,
                    Address      = usuario.Address,
                    CityId       = usuario.CityId,
                    DepartmentId = usuario.DepartmentId,
                    CountryId    = usuario.CountryId,
                    FirstName    = usuario.FirstName,
                    Genero       = usuario.Genero,
                    LastName     = usuario.LastName,
                    Phone        = usuario.Phone,
                    Photo        = usuario.Photo,
                    UserName     = usuario.UserName,
                    Password     = usuario.Password
                });

                var role = context.Roles.First(c => c.Name == "User").Id;

                var User = context.Users.Add(new IdentityUser("usuario")
                {
                    Email = newUsuario.UserName, EmailConfirmed = true
                });
                User.Roles.Add(new IdentityUserRole {
                    RoleId = role
                });

                await context.SaveChangesAsync();

                var store = new RedUserStore();
                await store.SetPasswordHashAsync(User, new RedUserManager().PasswordHasher.HashPassword(usuario.Password));

                return(Ok(new UsuarioViewModel(newUsuario)));
            }
        }