//public Patient checkIfPatientExists(int userId) //{ // using (var context = new HackathonEntities()) // { // return context.Patients.FirstOrDefault(x => x.UserId.Equals(userId)); // } //} public void createNewUserPharmacy(PharmacyCreationRequest request) { userRepository.createNewUser(request); var user = userRepository.getUserInfo(request.email); createNewPharmacy(request, user.id); }
public void createNewPharmacy(PharmacyCreationRequest request, int userId) { using (var context = new HackathonEntities()) { var pharmacy = new Pharmacy() { UserId = userId, Location = request.Location, Name = request.Name }; context.Pharmacies.Add(pharmacy); context.SaveChanges(); context.Dispose(); } }
public IHttpActionResult createPharmacy(PharmacyCreationRequest request) { var response = new HttpResponseMessage(); try { using (var context = new HackathonEntities()) { var exists = userRepository.checkIfUserExists(request.email); if (exists != null && exists.email.Length > 0) { response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "An account with this email already exists."); throw new HttpResponseException(response); } pharmacyRepository.createNewUserPharmacy(request); } return(Ok("success")); } catch (Exception e) { throw new HttpResponseException(response); } }