Exemple #1
0
        public async Task <ActionResult> Register(VetRegister vetRegister)
        {
            int userId = await PetApi.Instance.RegisterNewUser(new Credentials(vetRegister.Email, vetRegister.Password));

            VetRM castedVet = vetRegister;

            castedVet.UserId = userId;
            await PetApi.Instance.PostVet(castedVet);

            return(RedirectToAction("Login"));
        }
Exemple #2
0
 private Vet MapVetFromRM(VetRM vet)
 {
     return(new Vet()
     {
         firstname = vet.Firstname,
         lastname = vet.Lastname,
         licenseCode = vet.LicenseCode,
         licenseDate = vet.LicenseDate,
         RUC = vet.RUC,
         phone = vet.Phone
     });
 }
Exemple #3
0
        public IHttpActionResult PostVetProfile([FromBody] VetRM vet)
        {
            if (!ModelState.IsValid || vet == null)
            {
                return(BadRequest());
            }

            db.Connection.Open();
            using (db.Transaction = db.Connection.BeginTransaction())
            {
                try
                {
                    //  Check if user exists
                    var user = db.Users.FirstOrDefault(u => u.idUser == vet.UserId);
                    if (user == null)
                    {
                        db.Transaction.Rollback();
                        return(NotFound());
                    }

                    //  Insert new vet
                    Vet newVet = MapVetFromRM(vet);
                    db.Vets.InsertOnSubmit(newVet);
                    db.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);

                    //  Update user table to reference the new vet
                    user.Vet = newVet;
                    db.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);

                    //  If everything is OK, commit
                    db.Transaction.Commit();

                    return(Ok(newVet));
                }
                catch (Exception e)
                {
                    //  Rollback if something goes wrong
                    db.Transaction.Rollback();
                    return(InternalServerError(e));
                }
            }
        }
Exemple #4
0
 public async Task <Vet> PostVet(VetRM vet)
 {
     return(await PostApiAsync <Vet>(Uris.UriVets, vet));
 }