Esempio n. 1
0
        public ICommandResult Handle(CreateHospitalCommand command)
        {
            command.Validate();

            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, command.Notifications.Messages(), command));
            }

            Hospital hospital = new Hospital(command.FullName, command.Address, command.CNPJNumber, command.DocumentType);

            AddNotifications(hospital);

            if (Invalid)
            {
                return(new CommandResult(false, hospital.Notifications.Messages(), command));
            }

            _hospitalRepository.Add(hospital);

            _uow.Commit();

            return(new CommandResult(true, "Sucesso!", hospital));
        }
Esempio n. 2
0
 public void Add(Hospital hospital)
 {
     try
     {
         _hospitalRepository.Add(hospital);
         _logger.LogInformation("New hospital was added!");
     }
     catch (Exception exception)
     {
         _logger.LogError("An error occurred while adding the hospital" + " | " + exception);
         throw;
     }
 }
Esempio n. 3
0
        public async Task <IActionResult> CreateHospital([FromBody] HospitalSaveResource HospitalResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var hospital = mapper.Map <HospitalSaveResource, Entities.Models.Hospital>(HospitalResource);

            hospital.User = userManager.GetUserAsync(HttpContext.User).Result;

            repository.Add(hospital);
            await unitOfWork.CompleteAsync();

            hospital = await repository.GetHospital(hospital.Id);

            var result = mapper.Map <Entities.Models.Hospital, HospitalResource>(hospital);

            return(Created(nameof(GetHospital), result));
        }
Esempio n. 4
0
 public IActionResult Add([FromBody] Hospital hospital)
 {
     try
     {
         if (hospital == null)
         {
             return(StatusCode(StatusCodes.Status406NotAcceptable));
         }
         if (_hospitalRepository.GetAll().Any(r => r.HospitalName == hospital.HospitalName &&
                                              r.Email == hospital.Email))
         {
             return(Content("Hospital already exist"));
         }
         else
         {
             _hospitalRepository.Add(hospital);
             return(Content("Hospital registration successful"));
         }
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex));
     }
 }