public IActionResult AddDoctor(AddDoctorRequest addDoctorRequest) { _context.Doctor.Add(new Doctor { IdDoctor = addDoctorRequest.IdDoctor, FirstName = addDoctorRequest.FirstName, LastName = addDoctorRequest.LastName, Email = addDoctorRequest.Email }); return(Ok("Doktor dodany")); }
public DoctorResponse AddDoctor(AddDoctorRequest request) { var response = new DoctorResponse(); var doctor = _dbContext.Doctors.Add(new Doctor() { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }) .Entity; if (doctor != null) { _dbContext.SaveChanges(); response.IdDoctor = doctor.IdDoctor; response.FirstName = doctor.FirstName; response.LastName = doctor.LastName; response.Email = doctor.Email; } else { _dbContext.Remove(doctor); } return(response); }
public AddDoctorResponse AddDoctor(AddDoctorRequest doctorRequest) { var doctorExists = DoctorExists(Convert.ToInt32(doctorRequest.IdDoctor)); if (doctorExists) { int newId = GenerateNewDoctorId(); doctorRequest.IdDoctor = newId.ToString(); } var doctor = new Doctor() { IdDoctor = Convert.ToInt32(doctorRequest.IdDoctor), FirstName = doctorRequest.FirstName, LastName = doctorRequest.LastName, Email = doctorRequest.Email }; _context.Doctor.Add(doctor); _context.SaveChanges(); return(new AddDoctorResponse() { AssignedId = Convert.ToInt32(doctorRequest.IdDoctor), LastName = doctorRequest.LastName }); }
public bool MissingRequiredFields(AddDoctorRequest request, ref PdrValidationResult result) { var errors = new List <string>(); if (string.IsNullOrEmpty(request.FirstName)) { errors.Add("FirstName must be populated"); } if (string.IsNullOrEmpty(request.LastName)) { errors.Add("LastName must be populated"); } if (string.IsNullOrEmpty(request.Email)) { errors.Add("Email must be populated"); } if (errors.Any()) { result.PassedValidation = false; result.Errors.AddRange(errors); return(true); } return(false); }
public long AddDoctor(AddDoctorRequest request) { var validationResult = _validator.ValidateRequest(request); if (!validationResult.PassedValidation) { throw new ArgumentException(validationResult.Errors.First()); } Doctor doctor = new Doctor { FirstName = request.FirstName, LastName = request.LastName, Gender = (int)request.Gender, Email = request.Email, DateOfBirth = request.DateOfBirth, Orders = new List <Order>(), Created = request.Created }; _context.Doctor.Add(doctor); _context.SaveChanges(); return(doctor.Id); }
private bool ValidateGeneralFields(AddDoctorRequest request, ref PdrValidationResult result) { var errors = new List <string>(); if (string.IsNullOrEmpty(request.FirstName)) { errors.Add(ValidationErrorMessages.ShouldBePopulated(nameof(request.FirstName))); } if (string.IsNullOrEmpty(request.LastName)) { errors.Add(ValidationErrorMessages.ShouldBePopulated(nameof(request.LastName))); } if (string.IsNullOrEmpty(request.Email)) { errors.Add(ValidationErrorMessages.ShouldBePopulated(nameof(request.Email))); } else if (!Regex.IsMatch(request.Email, RegexValidation.EmailValidationRegexpPattern)) { errors.Add(ValidationErrorMessages.ProvideValidEmail); } if (errors.Any()) { result.PassedValidation = false; result.Errors.AddRange(errors); return(true); } return(false); }
public static List <Error> ValidateAddDoctorRequest(AddDoctorRequest doctorRequest) { var errors = new List <Error>(); if (!IsIdValid(doctorRequest.IdDoctor)) { errors.Add( new Error("IdDoctor", doctorRequest.IdDoctor.ToString(), "Invalid id format. Expected digits, Got: " + doctorRequest.IdDoctor)); } if (!IsFirstNameValid(doctorRequest.FirstName)) { errors.Add( new Error("FirstName", doctorRequest.FirstName, "Invalid First Name format. Expected format: " + NAME_REGEX + "; Got: " + doctorRequest.FirstName)); } if (!IsLastNameValid(doctorRequest.LastName)) { errors.Add( new Error("LastName", doctorRequest.LastName, "Invalid First Name format. Expected Format: " + NAME_REGEX + "; Got: " + doctorRequest.LastName)); } if (!IsEmailValid(doctorRequest.Email)) { errors.Add( new Error("Email", doctorRequest.Email, "Invalid Email format. Got: " + doctorRequest.LastName)); } return(errors); }
public bool MissingRequiredFields(AddDoctorRequest request, ref PdrValidationResult result) { var errors = new List <string>(); if (string.IsNullOrEmpty(request.FirstName)) { errors.Add("FirstName must be populated"); } if (string.IsNullOrEmpty(request.LastName)) { errors.Add("LastName must be populated"); } if (string.IsNullOrEmpty(request.Email)) { errors.Add("Email must be populated"); } else if (!Regex.IsMatch(request.Email, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")) //This probably would be better as a service, not duplicated. { errors.Add("Email must be a valid email address"); } if (errors.Any()) { result.PassedValidation = false; result.Errors.AddRange(errors); return(true); } return(false); }
private void DoctorAlreadyInDb(AddDoctorRequest request, ref PdrValidationResult result) { if (_context.Doctor.Any(x => x.Email == request.Email)) { result.PassedValidation = false; result.Errors.Add("A doctor with that email address already exists"); } }
public Doctor Add(Doctor doctor) { var request = new AddDoctorRequest(); request.Doctor = doctor; var response = HttpPost <AddDoctorRequest>("api/doctor/add", request, MediaType.Json); return(doctor); }
public void AddDoctor(AddDoctorRequest request) { DbContext.Add(new Doctor { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }); DbContext.SaveChanges(); }
public PdrValidationResult ValidateRequest(AddDoctorRequest request) { var result = new PdrValidationResult(true); MissingRequiredFields(request, ref result); DoctorAlreadyInDb(request, ref result); EmailValidationHelper.CheckEmailIsValid(request.Email, ref result); return(result); }
private bool EmailInvalid(AddDoctorRequest request, ref PdrValidationResult result) { if (!ValidationHelpers.Email(request.Email)) { result.PassedValidation = false; result.Errors.Add("Email must be a valid email address"); return(true); } return(false); }
public IActionResult AddDoctor(AddDoctorRequest req) { try { var doctor = _service.AddDoctor(req); return(Ok(doctor)); }catch (Exception ex) { return(BadRequest(ex.Message)); } }
public bool InvalidEmailAddress(AddDoctorRequest request, ref PdrValidationResult result) { if (_emailRegex.IsMatch(request.Email)) { return(false); } result.Errors.Add("Email must be a valid email address"); result.PassedValidation = false; return(true); }
private bool DoctorAlreadyInDb(AddDoctorRequest request, ref PdrValidationResult result) { if (_context.Doctor.Any(x => x.Email == request.Email)) { result.PassedValidation = false; result.Errors.Add(ValidationErrorMessages.EntityWithEmailAlreadyExists(nameof(Doctor))); return(true); } return(false); }
public Doctor AddDoctor(AddDoctorRequest request) { var doctor = new Doctor { IdDoctor = request.IdDoctor, FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }; _hospitalContext.Add(doctor); _hospitalContext.SaveChanges(); return(doctor); }
private bool EmailAddressNotValid(AddDoctorRequest request, ref PdrValidationResult result) { if (!_emailValidator.EmailAddressIsValid(request.Email, out var failureReason)) { result.PassedValidation = false; result.Errors.Add(failureReason); return(true); } return(false); }
private bool InvalidEmail(AddDoctorRequest request, ref PdrValidationResult result) { if (!Regex.IsMatch(request.Email, _emailPattern, RegexOptions.IgnoreCase)) { result.PassedValidation = false; result.Errors.Add("Email must be a valid email address"); return(true); } return(false); }
public IActionResult AddDoctor(AddDoctorRequest request) { if (dbService.AddDoctor(request)) { return(Ok("DOCTOR WAS ADDED")); } else { return(BadRequest("WRONG DATA")); } }
public IActionResult AddDoctor(AddDoctorRequest request) { var response = _dbService.AddDoctor(request); if (response != null) { return(Created("", response)); } return(BadRequest()); }
public IActionResult AddDoctor(AddDoctorRequest request) { var newDoctor = _contex.Doctors.Add(new Doctor() { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }); _contex.SaveChanges(); return(new CreatedAtActionResult("Add Doctor", "DoctorsController", new { idDoctor = newDoctor.Entity.IdDoctor }, newDoctor)); }
public IActionResult AddDoctor(AddDoctorRequest request) { try { var doctor = _service.AddDoctor(request); return(Created("AddDoctor", doctor)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult AddDoctor(AddDoctorRequest request) { try { Doctor doctor = _context.AddDoctor(request); return(Ok(doctor)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult AddDoctor(AddDoctorRequest request) { Doctor newDoctor = new Doctor(); newDoctor.FirstName = "Jakub"; newDoctor.LastName = "Michalski"; newDoctor.Email = "*****@*****.**"; request.doctor = newDoctor; var response = _serviceDoctor.AddDoctor(request); return(Ok(response.message)); }
public IActionResult CreateDoctor(AddDoctorRequest addDoctor) { Doctor doctor = new Doctor(); //var maxId = _context.Doctor.Max(doc => doc.IdDoctor); //doctor.IdDoctor = maxId + 1; doctor.FirstName = addDoctor.FirstName; doctor.LastName = addDoctor.LastName; doctor.Email = addDoctor.Email; _context.Doctor.Add(doctor); _context.SaveChanges(); return(Ok(doctor)); }
public bool EmailAddressInvalid(AddDoctorRequest request, ref PdrValidationResult result) { var emailAddressAttribute = new System.ComponentModel.DataAnnotations.EmailAddressAttribute(); if (!emailAddressAttribute.IsValid(request.Email)) { result.PassedValidation = false; result.Errors.Add("A valid email address must be supplied"); return(false); } return(true); }
public Doctor AddDoctor(AddDoctorRequest request) { _context = new DoctorsDbContext(); var doctor = new Doctor { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }; _context.Doctors.Add(doctor); _context.SaveChanges(); return(doctor); }
public IActionResult AddNewDoctor(AddDoctorRequest doctorRequest) { var errors = ValidationHelper.ValidateAddDoctorRequest(doctorRequest); if (errors.Count > 0) { return(StatusCode(400, errors)); } var addDoctorResponse = _doctorDbService.AddDoctor(doctorRequest); return(StatusCode(201, addDoctorResponse)); }
private bool EmailAddressInvalid(AddDoctorRequest request, ref PdrValidationResult result) { if (!Regex.IsMatch(request.Email, @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.IgnoreCase, System.TimeSpan.FromMilliseconds(250))) { result.PassedValidation = false; result.Errors.Add("Email must be a valid email address"); return(true); } return(false); }