Ejemplo n.º 1
0
        public async Task <Response> PostCitizen(Citizen citizen)
        {
            if (string.IsNullOrEmpty(citizen.DNI) || string.IsNullOrEmpty(citizen.Name) ||
                string.IsNullOrEmpty(citizen.LastName))
            {
                return(new Response {
                    Message = "Please enter the required values"
                });
            }
            var SavedCitizen = await _context.Citizen.FirstOrDefaultAsync(r => r.DNI == citizen.DNI);

            if (SavedCitizen != null)
            {
                return(new Response {
                    Message = "This citizen already exists in our system"
                });
            }

            if (citizen.DNI.Length > 13 || citizen.DNI.Length < 13)
            {
                return(new Response {
                    Message = "You need to enter a DNI of 13 digits"
                });
            }
            var post = await _context.NativeCity.FirstOrDefaultAsync(r => r.Id == citizen.IdNativeCity);

            citizen.NativeCity = post;
            _context.Citizen.Add(citizen);
            await _context.SaveChangesAsync();

            return(new Response {
                Message = "Added sucefully"
            });
        }
Ejemplo n.º 2
0
        public async Task <Response> PostNativeCity(NativeCity nativeCity)
        {
            var SavedNativeCity = await _context.NativeCity.FirstOrDefaultAsync(r => r.Name == nativeCity.Name);

            if (SavedNativeCity != null)
            {
                return(new Response {
                    Message = "This city already exists"
                });
            }

            _context.NativeCity.Add(nativeCity);
            await _context.SaveChangesAsync();

            return(new Response {
                Message = "Added sucefully"
            });
        }