Exemplo n.º 1
0
        public static void UpDataTo_db(BOLBranch oldBranch, BOLBranch newBranch)
        {
            try
            {
                using (RentalcarsEntities1 ef = new RentalcarsEntities1())
                {
                    Branch dbBranch = ef.Branches.FirstOrDefault(u => u.BranchesName == oldBranch.BranchesName);

                    if (dbBranch != null)
                    {
                        dbBranch.Address      = newBranch.Address;
                        dbBranch.Latitude     = newBranch.Latitude;
                        dbBranch.Longitude    = newBranch.Longitude;
                        dbBranch.BranchesName = newBranch.BranchesName;

                        ef.SaveChanges();
                    }
                    else
                    {
                        throw new InvalidOperationException($"this branch is not exist please change the values and try again");
                    }
                }
            }
            catch (Exception EX)
            {
                throw new Exception(EX.ToString());
            }
        }
Exemplo n.º 2
0
 public static void AddBranchTo_db(BOLBranch branch)
 {
     try {
         using (RentalcarsEntities1 ef = new RentalcarsEntities1())
         {
             Branch dbUser = ef.Branches.FirstOrDefault(u => u.BranchesName == branch.BranchesName);
             if (dbUser == null)
             {
                 ef.Branches.Add(new Branch
                 {
                     Address      = branch.Address,
                     Latitude     = branch.Latitude,
                     Longitude    = branch.Longitude,
                     BranchesName = branch.BranchesName
                 });
                 ef.SaveChanges();
             }
             else
             {
                 throw new InvalidOperationException($"this branch is exist please change the values and try again");
             }
         }
     }
     catch (Exception EX)
     {
         throw new Exception(EX.ToString());
     }
 }
Exemplo n.º 3
0
 public static void deleteFrom_db(BOLBranch BranchesName)
 {
     try
     {
         using (RentalcarsEntities1 ef = new RentalcarsEntities1())
         {
             Branch isExist = ef.Branches.FirstOrDefault(u => u.BranchesName == BranchesName.BranchesName);
             if (isExist != null)
             {
                 ef.Branches.Remove(isExist);
                 ef.SaveChanges();
             }
             else
             {
                 throw new InvalidOperationException($"this car type is not exist please change the values and try again");
             }
         }
     }
     catch (Exception EX)
     {
         throw new Exception(EX.ToString());
     }
 }
Exemplo n.º 4
0
 public IHttpActionResult Delete(BOLBranch branch)
 {
     RentBranches.deleteFrom_db(branch);
     return(Ok());
 }
Exemplo n.º 5
0
 public IHttpActionResult Post([FromBody] BOLBranch branch)
 {
     RentBranches.AddBranchTo_db(branch);
     return(Ok());
 }