Exemplo n.º 1
0
        public SaveOrderResponse PerformCreateNewOrder(SaveOrderRequest request)
        {
            SaveOrderResponse response = new SaveOrderResponse();

            try
            {
                using (var db = new CuddlyWombatEntities())
                {
                    db.Configuration.LazyLoadingEnabled   = false;
                    db.Configuration.ProxyCreationEnabled = false;

                    db.Orders.Add(request.Order);
                    db.SaveChanges();

                    foreach (var o in request.OrderMenuItems)
                    {
                        o.OrderID = request.Order.OrderID;
                        db.OrderMenuItems.Add(o);
                    }

                    db.SaveChanges();

                    response.MessageString   = "New Order is successfully created";
                    response.MessageStatusID = (byte)EMessageStatus.Success;
                }
            }
            catch (Exception ex)
            {
                response.MessageStatusID = (byte)EMessageStatus.Exception;
                response.MessageString   = ex.Message;
            }

            return(response);
        }
Exemplo n.º 2
0
        public ActionResult Registration(CustomerRegistration model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var db = new CuddlyWombatEntities())
                    {
                        var existingUser = (from u in db.Users
                                            where u.Email == model.Email
                                            select u).FirstOrDefault();

                        if (existingUser != null)
                        {
                            ModelState.AddModelError("", "Existing Internal User.");
                            return(View());
                        }
                        else
                        {
                            var existingCustomer = (from c in db.Customers
                                                    where c.Email == model.Email
                                                    select c).FirstOrDefault();

                            if (existingCustomer != null)
                            {
                                ModelState.AddModelError("", "Existing Customer.");
                                return(View());
                            }
                        }

                        var encryptedPassword = CustomEnrypt.Encrypt(model.Password);
                        var customer          = new Customer
                        {
                            Email       = model.Email,
                            Password    = encryptedPassword,
                            GivenName   = model.GivenName,
                            Surname     = model.Surname,
                            DateCreated = DateTime.Now
                        };
                        db.Customers.Add(customer);
                        db.SaveChanges();
                    }
                    return(RedirectToAction("Login", "Auth"));
                }
                else
                {
                    ModelState.AddModelError("", "One or more fields have been");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Exception", ex.Message);
            }
            return(View());
        }
Exemplo n.º 3
0
        public SaveMenuItemResponse PerformCreateNewMenuItem(SaveMenuItemRequest request)
        {
            SaveMenuItemResponse response = new SaveMenuItemResponse();

            try
            {
                using (var db = new CuddlyWombatEntities())
                {
                    db.Configuration.LazyLoadingEnabled   = false;
                    db.Configuration.ProxyCreationEnabled = false;

                    if (request.MenuItemID == 0)
                    {
                        var menuItem = new MenuItem()
                        {
                            Name        = request.Name,
                            Description = request.Description,
                            Price       = request.Price,
                            DateCreated = DateTime.Now,
                            IsUsed      = true,
                            PreparationTimeInMinutes = request.PreparationTimeInMinutes
                        };

                        db.MenuItems.Add(menuItem);
                    }
                    else
                    {
                        var menuItem = (from m in db.MenuItems
                                        where m.MenuItemID == request.MenuItemID
                                        select m).FirstOrDefault();

                        menuItem.Name        = request.Name;
                        menuItem.Description = request.Description;
                        menuItem.Price       = request.Price;
                        menuItem.IsUsed      = true;
                        menuItem.PreparationTimeInMinutes = request.PreparationTimeInMinutes;
                    }
                    response.MenuItems = (from m in db.MenuItems
                                          select m).ToList();

                    db.SaveChanges();

                    response.MessageString   = "New Menu Item is successfully added to the database";
                    response.MessageStatusID = (byte)EMessageStatus.Success;
                }
            }
            catch (Exception ex)
            {
                response.MessageStatusID = (byte)EMessageStatus.Exception;
                response.MessageString   = ex.Message;
            }
            return(response);
        }
        public SaveMenuItemResponse PerformUpdateReservationStatus(UpdateReservationRequest request)
        {
            SaveMenuItemResponse response = new SaveMenuItemResponse();
            var modifiedDate = DateTime.Now;

            try
            {
                using (var db = new CuddlyWombatEntities())
                {
                    db.Configuration.LazyLoadingEnabled   = false;
                    db.Configuration.ProxyCreationEnabled = false;

                    var reservationToUpdate = (from r in db.Reservations
                                               where r.ReservationID == request.ReservationID
                                               select r).FirstOrDefault();

                    if (reservationToUpdate != null)
                    {
                        var reservationHistory = new ReservationHistory()
                        {
                            ReservationID       = reservationToUpdate.ReservationID,
                            CustomerID          = reservationToUpdate.CustomerID,
                            NumberOfTables      = reservationToUpdate.NumberOfTables,
                            ReservationDate     = reservationToUpdate.ReservationDate,
                            ReservationStatusID = reservationToUpdate.ReservationStatusID,
                            DateCreated         = reservationToUpdate.DateCreated,
                            DateModified        = modifiedDate
                        };

                        db.ReservationHistories.Add(reservationHistory);
                        reservationToUpdate.ReservationStatusID = request.ReservationStatusID;
                        reservationToUpdate.DateModified        = modifiedDate;
                    }
                    else
                    {
                        response = new SaveMenuItemResponse()
                        {
                            MessageString   = "Please select a reservation",
                            MessageStatusID = (byte)EMessageStatus.Success
                        };
                        return(response);
                    }

                    db.SaveChanges();

                    if (request.ReservationStatusID == (byte)EReservationStatus.Canceled)
                    {
                        response.MessageString = "Reservation is cancelled";
                    }
                    else if (request.ReservationStatusID == (byte)EReservationStatus.Completed)
                    {
                        response.MessageString = "Reservation Status updated to Completed";
                    }

                    response.MessageStatusID = (byte)EMessageStatus.Success;
                }
            }
            catch (Exception ex)
            {
                response.MessageStatusID = (byte)EMessageStatus.Exception;
                response.MessageString   = ex.Message;
            }

            return(response);
        }
        public CreateNewReservationResponse PerformCreateNewReservation(CreateNewReservationRequest request)
        {
            CreateNewReservationResponse response = new CreateNewReservationResponse();
            var createdDate = DateTime.Now;

            try
            {
                using (var db = new CuddlyWombatEntities())
                {
                    db.Configuration.LazyLoadingEnabled   = false;
                    db.Configuration.ProxyCreationEnabled = false;



                    var totalTables = (from t in db.Tables
                                       where t.IsAvailable == true
                                       select t).ToList();

                    int totalTableCount = totalTables.Count();

                    var customer = (from c in db.Customers
                                    where c.CustomerID == request.Reservation.CustomerID
                                    select c).FirstOrDefault();

                    if (customer == null)
                    {
                        response.MessageString   = "Cannot find the customer";
                        response.MessageStatusID = (byte)EMessageStatus.Fail;

                        return(response);
                    }

                    if (totalTableCount < request.Reservation.NumberOfTables)
                    {
                        response.MessageString   = "Maximum tables you can book is " + totalTableCount;
                        response.MessageStatusID = (byte)EMessageStatus.Fail;

                        return(response);
                    }

                    var allReservationsForGivenDate = (from r in db.Reservations
                                                       where r.ReservationDate == request.Reservation.ReservationDate
                                                       select r).ToList();

                    var allAvailableTablesForGivenDate = 0;
                    var allReservedTablesForGivenDate  = 0;

                    foreach (var r in allReservationsForGivenDate)
                    {
                        allReservedTablesForGivenDate = allReservedTablesForGivenDate + r.NumberOfTables;
                    }
                    allAvailableTablesForGivenDate = totalTableCount - allReservedTablesForGivenDate;

                    if (allAvailableTablesForGivenDate < request.Reservation.NumberOfTables)
                    {
                        response.MessageString   = "No available tables for the selected date, Please select a different date.";
                        response.MessageStatusID = (byte)EMessageStatus.Fail;
                        return(response);
                    }

                    var reservation = new Reservation()
                    {
                        ReservationID       = 0,
                        CustomerID          = request.Reservation.CustomerID,
                        ReservationStatusID = request.Reservation.ReservationStatusID,
                        ReservationDate     = request.Reservation.ReservationDate,
                        NumberOfTables      = request.Reservation.NumberOfTables,
                        DateCreated         = createdDate
                    };

                    db.Reservations.Add(reservation);
                    db.SaveChanges();

                    response.MessageString   = "Reservation successfully added";
                    response.MessageStatusID = (byte)EMessageStatus.Success;
                }
            }
            catch (Exception ex)
            {
                response.MessageStatusID = (byte)EMessageStatus.Exception;
                response.MessageString   = ex.Message;
            }

            return(response);
        }
Exemplo n.º 6
0
        public SaveMenuResponse PerformCreateNewMenu(SaveMenuRequest request)
        {
            SaveMenuResponse response = new SaveMenuResponse();
            var menu          = new Menu();
            var menuMenuItems = new List <MenuMenuItem>();

            try
            {
                using (var db = new CuddlyWombatEntities())
                {
                    db.Configuration.LazyLoadingEnabled   = false;
                    db.Configuration.ProxyCreationEnabled = false;

                    if (request.MenuID == 0)
                    {
                        menu.MenuID      = 0;
                        menu.Name        = request.Name;
                        menu.MenuTypeID  = request.MenuTypeID;
                        menu.Description = request.Description;
                        menu.DateCreated = DateTime.Now;
                        menu.IsUsed      = true;
                        db.Menus.Add(menu);
                        db.SaveChanges();
                    }
                    else
                    {
                        menu = (from m in db.Menus
                                where m.MenuID == request.MenuID
                                select m).FirstOrDefault();

                        menu.Name        = request.Name;
                        menu.MenuTypeID  = request.MenuTypeID;
                        menu.Description = request.Description;
                        menu.IsUsed      = true;

                        var allAssignedMenuItems = (from m in db.MenuMenuItems
                                                    where m.MenuID == request.MenuID
                                                    select m).ToList();

                        foreach (var selectedMenuItem in allAssignedMenuItems)
                        {
                            db.MenuMenuItems.Remove(selectedMenuItem);
                        }
                    }
                    foreach (var mi in request.MenuItemIDs)
                    {
                        var menuMenuItem = new MenuMenuItem()
                        {
                            MenuID     = menu.MenuID,
                            MenuItemID = mi
                        };
                        menuMenuItems.Add(menuMenuItem);
                    }
                    db.MenuMenuItems.AddRange(menuMenuItems);
                    db.SaveChanges();

                    response.Menus = (from m in db.Menus.Include("MenuType")
                                      select m).ToList();

                    foreach (var menu_ in response.Menus)
                    {
                        menu_.MenuType.Menus = null;

                        menu_.MenuItems = (from m in db.MenuMenuItems
                                           join mi in db.MenuItems on m.MenuItemID equals mi.MenuItemID
                                           where m.MenuID == menu.MenuID
                                           select mi).ToList();
                    }

                    response.MessageString   = "New Menu is successfully added to the database";
                    response.MessageStatusID = (byte)EMessageStatus.Success;
                }
            }
            catch (Exception ex)
            {
                response.MessageStatusID = (byte)EMessageStatus.Exception;
                response.MessageString   = ex.Message;
            }
            return(response);
        }
Exemplo n.º 7
0
        public SaveOrderResponse PerformUpdateOrderStatus(UpdateOrderRequest request)
        {
            SaveOrderResponse response = new SaveOrderResponse();
            var modifiedDate           = DateTime.Now;

            try
            {
                using (var db = new CuddlyWombatEntities())
                {
                    db.Configuration.LazyLoadingEnabled   = false;
                    db.Configuration.ProxyCreationEnabled = false;

                    var orderToUpdate = (from o in db.Orders
                                         where o.OrderID == request.OrderID
                                         select o).FirstOrDefault();

                    if (orderToUpdate != null)
                    {
                        var orderHistory = new OrderHistory()
                        {
                            OrderID       = orderToUpdate.OrderID,
                            TableID       = orderToUpdate.TableID,
                            CustomerID    = orderToUpdate.CustomerID,
                            OrderTypeID   = orderToUpdate.OrderTypeID,
                            OrderStatusID = orderToUpdate.OrderStatusID,
                            TotalPrice    = orderToUpdate.TotalPrice,
                            PickUpTime    = orderToUpdate.PickUpTime,
                            IsPaid        = orderToUpdate.IsPaid,
                            DateCreated   = orderToUpdate.DateCreated,
                            DateModified  = modifiedDate
                        };

                        db.OrderHistories.Add(orderHistory);
                        orderToUpdate.OrderStatusID = request.OrderStatusID;
                        orderToUpdate.DateModified  = modifiedDate;
                    }
                    else
                    {
                        response.MessageString   = "Please select an order";
                        response.MessageStatusID = (byte)EMessageStatus.Fail;

                        return(response);
                    }

                    db.SaveChanges();

                    if (request.OrderStatusID == (byte)EOrderStatus.Canceled)
                    {
                        response.MessageString = "Order is cancelled";
                    }
                    else if (request.OrderStatusID == (byte)EOrderStatus.Completed)
                    {
                        response.MessageString = "Order Status updated to Completed";
                    }
                    response.MessageStatusID = (byte)EMessageStatus.Success;
                }
            }
            catch (Exception ex)
            {
                response.MessageStatusID = (byte)EMessageStatus.Exception;
                response.MessageString   = ex.Message;
            }

            return(response);
        }