Ejemplo n.º 1
0
        public ActionResult <String> Create([FromBody] User user)
        {
            //creates user object from the request
            //Checks if email or phone exists in database
            bool emailCheck = false;
            bool phoneCheck = false;

            emailCheck = motherload.Users.Any(User => User.Email == user.Email);
            phoneCheck = motherload.Users.Any(User => User.PhoneNumber == user.PhoneNumber);

            if (emailCheck)
            {
                return("email");
            }
            else if (phoneCheck)
            {
                return("phone");
            }
            //if everything is fine, adds new user to database and sends back "created"
            else
            {
                motherload.Users.Add(user);
                motherload.SaveChanges();
                return("created");
            }
        }
Ejemplo n.º 2
0
        public ActionResult <String> CreateRide([FromBody] Ride ride)
        {
            bool alreadyInDb = (from p in motherload.Rides where p.Driver == ride.Driver &&
                                p.Date == ride.Date && p.Time == ride.Time select p).Count() > 0;

            if (alreadyInDb)
            {
                return("alreadyExists");
            }
            else
            {
                motherload.Rides.Add(ride);
                motherload.SaveChanges();
                return("created");
            }
        }
Ejemplo n.º 3
0
 public ActionResult <String> Delete([FromBody] Ride request)
 {
     try{
         var query = from r in motherload.Rides
                     where (r.Driver == request.Driver && r.Time == request.Time && r.Date == request.Date)
                     select r;
         Ride ride = new Ride();
         foreach (var q in query)
         {
             ride = q;
         }
         motherload.Rides.Remove(ride);
         motherload.SaveChanges();
         return("ok");
     }
     catch (Exception e) {
         return("bad");
     }
 }
Ejemplo n.º 4
0
 public ValuesController(MotherloadContext motherload)
 {
     this.motherload = motherload;
     if (motherload.Users.Count() == 0)
     {
         // Create a new User if collection is empty,
         // which means you can't delete all People.
         motherload.Users.Add(new User {
             Name  = "Mihail Kanchev", Password = "******",
             Email = "*****@*****.**", PhoneNumber = "69696969"
         });
         motherload.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public UsersController(MotherloadContext motherload)
 {
     this.motherload = motherload;
     if (motherload.Users.Count() == 0)
     {
         // Create a new User if collection is empty,
         // which means you can't delete all People.
         motherload.Users.Add(new User {
             Name  = "Admin", Password = "******",
             Email = "admin", PhoneNumber = "admin"
         });
         motherload.SaveChanges();
     }
 }