예제 #1
0
        public ActionResult EditCustomer(string id)
        {
            PiniTCustomer customer = cusDb.GetCustomer(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }
            return(View(customer));
        }
        public ActionResult Put(int id, [FromBody] Customer customer)
        {
            CustomerContext context        = HttpContext.RequestServices.GetService(typeof(CustomerContext)) as CustomerContext;
            Customer        customerFromDB = context.GetCustomer(id);

            if (customer.name == null || customer.surname == null)
            {
                return(BadRequest(Json(new { status = "error", message = "Customer name/surname is missing" })));
            }

            if (customerFromDB == null)
            {
                return(NotFound("Customer with ID " + id + " not found"));
            }

            else
            {
                if (context.UpdateCustomer(id, customer))
                {
                    customer.id = id;
                    return(Ok(customer));
                }
                else
                {
                    return(NotFound("Customer with ID " + id + " not found"));
                }
            }
        }
예제 #3
0
        public ActionResult Create(CreateReservationsVM vm)
        {
            Table         table    = tableDb.GetTable((int)TempData["TableId"]);
            PiniTCustomer customer = custDb.GetCustomer(User.Identity.GetUserId());
            var           manager  = manDb.GetManager(table.RestaurantId);
            var           hub      = GlobalHost.ConnectionManager.GetHubContext <PiniTHub>();

            if (!ModelState.IsValid || !vm.HasAcceptedTerms)
            {
                TempData["TableId"] = table.TableId;
                vm.Table            = table;
                vm.Restaurant       = restDb.GetRestaurant(table.RestaurantId);
                return(View(vm));
            }

            if (customer.AccountWallet.Credits < vm.Reservation.BookingFee)
            {
                TempData["Message"] = "Not enough Credits. Reservation Cancelled";
                return(RedirectToAction("CustomerIndex", "Tables", new { id = table.RestaurantId }));
            }

            if (table.IsBooked)
            {
                TempData["Message"] = "Sorry! Someone else Booked that Table! You can Book another one :)";
                return(RedirectToAction("CustomerIndex", "Tables", new { id = table.RestaurantId }));
            }

            vm.Reservation.TableId = table.TableId;
            tableDb.ToggleIsBooked(vm.Reservation.TableId);
            vm.Reservation.CustomerId = User.Identity.GetUserId();
            if (vm.Reservation.Comment == null || vm.Reservation.Comment == "")
            {
                vm.Reservation.Comment = "No Comment";
            }
            db.CreateReservation(vm.Reservation);
            hub.Clients.User(manager.UserName).getReservation(new
            {
                Customer      = User.Identity.Name,
                Comment       = vm.Reservation.Comment,
                Date          = vm.Reservation.BookDate.ToString("dd/MM/yyyy HH:mm"),
                Table         = table.Name,
                EstimatedTime = vm.Reservation.BookDate.AddMinutes(vm.EstimatedTime).ToString("HH:mm")
            });
            bool result = walletDb.PayFee(vm.Reservation.BookingFee, vm.Reservation.CustomerId, table.RestaurantId);

            if (result)
            {
                TempData["Message"] = "Reservation Accepted! :)";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                TempData["Message"] = "Sorry Something went Wrong ! :'(";
                return(RedirectToAction("CustomerIndex", "Tables", new { id = table.RestaurantId }));
            }
        }
        // GET api/customers/5
        public HttpResponseMessage Get(int id)
        {
            var cust = _Repository.GetCustomer(id);

            if (cust == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(Request.CreateResponse <Customer>(HttpStatusCode.OK, cust));
        }
        public ActionResult Get(int id)
        {
            CustomerContext context  = HttpContext.RequestServices.GetService(typeof(CustomerContext)) as CustomerContext;
            Customer        customer = context.GetCustomer(id);

            if (customer != null)
            {
                return(Ok(customer));
            }
            else
            {
                return(NotFound("Customer with ID " + id + " not found"));
            }
        }
예제 #6
0
 public Task <CustomerGraph> Customer([Inject] CustomerContext service) => service.GetCustomer(_dto.CustomerId);
 public IActionResult Index()
 {
     return(Ok(_context.GetCustomer()));
 }