public ActionResult Create(Restaurant restaurant)
 {
     if (ModelState.IsValid)
     {
         _db.Restaurants.Add(restaurant);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(restaurant));
 }
 public ActionResult Create([Bind(Include = "RestaurantID,Name,Address,Rating")] Restaurant restaurant)
 {
     if (ModelState.IsValid)
     {
         db.Restaurants.Add(restaurant);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(restaurant));
 }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "ID,name,location,no_of_rooms,no_of_staff")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                db.Restaurants.Add(restaurant);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(restaurant));
        }
Beispiel #4
0
        [ValidateAntiForgeryToken] //protects fields from being used to pull data out of database

        //This method (below) will run once "Create" button is pressed
        public ActionResult Create([Bind(Include = "RestaurantID,Name,Address,Rating")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                db.Restaurants.Add(restaurant);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(restaurant));
            //if form is not valid, you will return back to "create" page with entered data
            //and error message showing which part of the form is invalid
        }
Beispiel #5
0
 public ActionResult New([Bind(Exclude = "Data")] Reservation reservation)
 {
     reservation.Data = DateTime.Now;
     try
     {
         db.Reservations.Add(reservation);
         db.SaveChanges();
         TempData["message"] = "Reservation cu titlul " + reservation.Titlu + " a fost adaugat cu succes";
         return(RedirectToAction("AfisareReservations"));
     }
     catch (Exception e)
     {
         reservation.Restaurants = GetAllRestaurants();
         return(View(reservation));
     }
 }
Beispiel #6
0
        public bool CreateOrder(Order order)
        {
            bool isCreated = false;

            objRestaurantContext.orderEntity.Add(order);
            try
            {
                objRestaurantContext.SaveChanges();
                isCreated = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(isCreated);
        }
 public HttpResponseMessage PostReview([FromBody] Users us)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (var ctx = new RestaurantDBContext())
             {
                 ctx.Users.Add(us);
                 ctx.SaveChanges();
                 var message = Request.CreateResponse(HttpStatusCode.Created, us);
                 message.Headers.Location = new Uri(Request.RequestUri + us.Id.ToString());
                 return(message);
             }
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Invalid Model"));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
     }
 }
        public HttpResponseMessage PostRestaurant([FromBody] Restaurant rest)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var ctx = new RestaurantDBContext())
                    {
                        ctx.Restaurants.Add(new Restaurant()
                        {
                            RestaurantName = rest.RestaurantName,
                            City           = rest.City
                        });

                        ctx.SaveChanges();
                        var message = Request.CreateResponse(HttpStatusCode.Created, rest);
                        message.Headers.Location = new Uri(Request.RequestUri + rest.RestaurantName);
                        return(message);
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Invalid Model"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public HttpResponseMessage DeleteReview(int id)
        {
            try
            {
                using (var ctx = new RestaurantDBContext())
                {
                    Users us = ctx.Users.SingleOrDefault(b => b.Id == id);

                    if (us == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User with id =" + id.ToString() + "not found to delete"));
                    }
                    else
                    {
                        ctx.Users.Remove(us);
                        ctx.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Beispiel #10
0
 public static void AddOrder(OrderObj order)
 {
     try
     {
         using (var context = new RestaurantDBContext())
         {
             context.OrderObjs.Add(order);
             context.SaveChanges();
         }
     }
     catch
     {
         return;
     }
 }
 public void AddOrder(Orders o)
 {
     context.Orders.Add(o);
     context.SaveChanges();
 }
Beispiel #12
0
 public void Add(T entity)
 {
     dbSet.Add(entity);
     _dBConn.SaveChanges();
 }
 public bool Create(PdbBookTable ban)
 {
     _context.PdbBookTables.Add(ban);
     _context.Entry(ban).State = System.Data.Entity.EntityState.Added;
     return(_context.SaveChanges() == 1);
 }
 private ActionResult SaveAndRedirect()
 {
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Beispiel #15
0
 public void Save()
 {
     db.SaveChanges();
 }
 public bool Create(PdbRestaurant res)
 {
     _context.PdbRestaurants.Add(res);
     _context.Entry(res).State = System.Data.Entity.EntityState.Added;
     return(_context.SaveChanges() == 1);
 }
Beispiel #17
0
 public bool Remove(T entity)
 {
     dBContext.Set <T>().Remove(entity);
     return(dBContext.SaveChanges() > 0);
 }
Beispiel #18
0
 public bool Create(PdbFood fo)
 {
     _context.PdbFoods.Add(fo);
     _context.Entry(fo).State = System.Data.Entity.EntityState.Added;
     return(_context.SaveChanges() == 1);
 }
Beispiel #19
0
 public void Save()
 {
     _dBConn.SaveChanges();
 }