Ejemplo n.º 1
0
        // POST api/Default1
        public HttpResponseMessage PostOrder(IList<CartItem> cartItems)
        {
            if (ModelState.IsValid)
            {
                var user = new UserProfile();
                using (CanteenContext ctx = new CanteenContext())
                {
                    user = (from o in ctx.UserProfiles orderby o.UserId where o.UserName == User.Identity.Name select o).ToList().FirstOrDefault();
                }
                db.Entry(user).State = EntityState.Unchanged;
                var order = new Order()
                {
                    DateConfirmed = DateTime.Now,
                    DateCreated = DateTime.Now,
                    DateDelivered = DateTime.Now,
                    IsConfirmed = false,
                    IsDelivered = false,

                    User = user
                };
                db.Orders.Add(order);
                db.SaveChanges();

                foreach (var i in cartItems)
                {
                    var orderItem = new OrderItem()
                    {
                        MenuItemId = i.Id,
                        OrderId = order.OrderId,
                        Quantity = i.Quantity
                    };

                    db.OrderItems.Add(orderItem);
                }

                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, cartItems);
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 2
0
        public ActionResult IndexEmployee()
        {
            var orders = new List<Order>();
            var fullOrders = new List<OrderDTO>();
            using (CanteenContext ctx = new CanteenContext())
            {
                orders = (from o in ctx.Orders.Include("User") orderby o.OrderId where o.IsDelivered == false && o.User.Blocked == false select o).ToList();
            }

            foreach (var order in orders)
            {
                var fullOrder = new OrderDTO(order);
                var orderItems = new List<OrderItemDTO>();
                if (order.User != null)
                    fullOrders.Add(fullOrder);
            }
            return View("IndexEmployee", fullOrders);
        }
Ejemplo n.º 3
0
        public ActionResult IndexCustomerActive()
        {
            var user = new UserProfile();
            using (CanteenContext ctx = new CanteenContext())
            {
                user = (from o in ctx.UserProfiles orderby o.UserId where o.UserName == User.Identity.Name select o).ToList().FirstOrDefault();
            }
            var orders = new List<Order>();

            using (CanteenContext ctx = new CanteenContext())
            {
                orders = (from o in ctx.Orders.Include("User") orderby o.OrderId where o.User.UserId == user.UserId && o.IsDelivered == false select o).ToList();
            }
            var fullOrders = new List<OrderDTO>();

            foreach (var order in orders)
            {
                var fullOrder = new OrderDTO(order);
                var orderItems = new List<OrderItemDTO>();
                using (CanteenContext ctx = new CanteenContext())
                {
                    var orderItemsFull = (from o in ctx.OrderItems orderby o.OrderItemId where o.OrderId == fullOrder.OrderId select o).ToList();
                    foreach (var i in orderItemsFull)
                    {
                        var menuItem = (from o in ctx.MenuItems orderby o.MenuItemId where o.MenuItemId == i.MenuItemId select o).ToList().FirstOrDefault();
                        var orderX = new OrderItemDTO(i);
                        orderX.MenuItem = menuItem;
                        if (menuItem != null)
                            orderItems.Add(orderX);
                    }

                }
                fullOrder.OrderItems = orderItems;
                if (fullOrder.OrderItems.Count() > 0)
                    fullOrders.Add(fullOrder);
            }
            return View("IndexCustomer", fullOrders);
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            var orders = db.Orders.ToList();
            var fullOrders = new List<OrderDTO>();

            foreach (var order in orders)
            {
                var fullOrder = new OrderDTO(order);
                var orderItems = new List<OrderItemDTO>();
                using (CanteenContext ctx = new CanteenContext())
                {
                    var orderItemsFull = (from o in ctx.OrderItems orderby o.OrderItemId where o.OrderId == fullOrder.OrderId select o).ToList();
                    foreach (var i in orderItemsFull)
                    {
                        var menuItem = (from o in ctx.MenuItems orderby o.MenuItemId where o.MenuItemId == i.MenuItemId select o).ToList().FirstOrDefault();
                        var orderX = new OrderItemDTO(i);
                        orderX.MenuItem = menuItem;
                        if (menuItem != null)
                            orderItems.Add(orderX);
                    }

                }
                fullOrder.OrderItems = orderItems;
                if (fullOrder.OrderItems.Count() > 0)
                    fullOrders.Add(fullOrder);
            }
            return View(fullOrders);
        }
Ejemplo n.º 5
0
        public ActionResult EditEmployee(int id = 0)
        {
            Order order = db.Orders.Find(id);

            if (order == null)
            {
                return HttpNotFound();
            }
            var fullOrder = new OrderDTO(order);

            var orderItems = new List<OrderItemDTO>();
            var orderItemsSorted = new List<OrderItemDTO>();
            using (CanteenContext ctx = new CanteenContext())
            {
                var orderItemsFull = (from o in ctx.OrderItems orderby o.OrderItemId where o.OrderId == fullOrder.OrderId select o).ToList();
                foreach (var i in orderItemsFull)
                {
                    var menuItem = (from o in ctx.MenuItems orderby o.MenuItemId where o.MenuItemId == i.MenuItemId select o).ToList().FirstOrDefault();
                    var orderX = new OrderItemDTO(i);
                    orderX.MenuItem = menuItem;
                    if (menuItem != null)
                    {
                        orderItems.Add(orderX);
                    }
                }

            }
            if (orderItems.Count > 0)
            {

                fullOrder.OrderItems = orderItems.OrderBy(o => o.MenuItemId).ToList();

            }
            return View(fullOrder);
            /* orig
            Order order = db.Orders.Find(id);
            if (order == null)
            {
                return HttpNotFound();
            }

            return View(order);*/
        }
Ejemplo n.º 6
0
 //
 // GET: /Profile/Create
 private UserProfile _getCurrentUser()
 {
     var userprofile = new UserProfile();
     using (CanteenContext ctx = new CanteenContext())
     {
         userprofile = (from o in ctx.UserProfiles orderby o.UserId where o.UserName == User.Identity.Name select o).ToList().FirstOrDefault();
     }
     return userprofile;
 }
Ejemplo n.º 7
0
 public ActionResult MyDetails()
 {
     var userprofile = new UserProfile();
     using (CanteenContext ctx = new CanteenContext())
     {
         userprofile = (from o in ctx.UserProfiles orderby o.UserId where o.UserName == User.Identity.Name select o).ToList().FirstOrDefault();
     }
     if (userprofile == null)
     {
         return HttpNotFound();
     }
     return View(userprofile);
 }
Ejemplo n.º 8
0
        public ActionResult IndexCustomer()
        {
            var users = new List<UserProfile>();
            var usersDTO = new List<UserProfileDTO>();
            using (CanteenContext ctx = new CanteenContext())
            {
                var usernames = Roles.GetUsersInRole("Client");
                 foreach (var user in usernames)
                {

                var userprofile = (from o in ctx.UserProfiles where o.UserName == user select o).ToList().FirstOrDefault();
                if (userprofile != null) {
                    usersDTO.Add(new UserProfileDTO( userprofile));
                }
                }

            }
            return View("Index",usersDTO);
        }
Ejemplo n.º 9
0
        //
        // GET: /Statistics/
        public ActionResult Index()
        {
            Statistics statistics = new Statistics();
            var today = new DateTime();
            //var dayOrders = new List<Order>();
            //var monthOrders = new List<Order>();
            //var fullOrderDay = new List<OrderDTO>();
            //var fullOrderMonth = new List<OrderDTO>();
            using (CanteenContext ctx = new CanteenContext())
            {

                statistics.TotalNumberOfUsers = (from o in ctx.UserProfiles select o).Count();
                statistics.TotalNumberOfOrders = (from o in ctx.OrderItems select o).Count();
                statistics.TotalSalesToday = (from o in ctx.Orders where o.IsDelivered == true && o.DateDelivered.Day == today.Day select o).Count();
                statistics.TotalSalesThisMonth = (from o in ctx.Orders where o.IsDelivered == true && o.DateDelivered.Month == today.Month select o).Count();

                var dayOrders = (from o in ctx.Orders where o.IsDelivered == true && o.DateDelivered.Day == today.Day select o).ToList();
                var monthOrders = (from o in ctx.Orders where o.IsDelivered == true && o.DateDelivered.Month == today.Month select o).ToList();

                var orderItemsDay = new List<OrderItemDTO>();
                var orderItemsMonth = new List<OrderItemDTO>();
                var orderItemsDayFull = new List<OrderItem>();
                var orderItemsMonthFull = new List<OrderItem>();
                var fullOrderDay = new List<OrderDTO>();
                var fullOrderMonth = new List<OrderDTO>();

                foreach (var i in dayOrders)
                {
                    fullOrderDay.Add(new OrderDTO(i));
                }
                foreach (var i in monthOrders)
                {
                    fullOrderMonth.Add(new OrderDTO(i));
                }

                foreach (var i in fullOrderDay)
                {
                    orderItemsDayFull = (from o in ctx.OrderItems orderby o.OrderItemId where o.OrderId == i.OrderId select o).ToList();
                }
                foreach (var i in fullOrderMonth)
                {
                    orderItemsMonthFull = (from o in ctx.OrderItems orderby o.OrderItemId where o.OrderId == i.OrderId select o).ToList();
                }

                foreach (var i in orderItemsDayFull)
                {
                    var menuItem = (from o in ctx.MenuItems orderby o.MenuItemId where o.MenuItemId == i.MenuItemId select o).ToList().FirstOrDefault();
                    var orderX = new OrderItemDTO(i);
                    orderX.MenuItem = menuItem;
                    if (menuItem != null)
                    {
                        orderItemsDay.Add(orderX);
                    }
                }
                foreach (var i in orderItemsMonthFull)
                {
                    var menuItem = (from o in ctx.MenuItems orderby o.MenuItemId where o.MenuItemId == i.MenuItemId select o).ToList().FirstOrDefault();
                    var orderX = new OrderItemDTO(i);
                    orderX.MenuItem = menuItem;
                    if (menuItem != null)
                    {
                        orderItemsMonth.Add(orderX);
                    }
                }

                if (orderItemsDay.Count > 0)
                {
                    foreach (var i in orderItemsDay)
                    {

                    }
                }

                //db.Statistics.Add(statistics);
                //db.SaveChanges();

            }
            return View("Details", statistics);
        }
Ejemplo n.º 10
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            var userprofile = new UserProfile();
            using (CanteenContext ctx = new CanteenContext())
            {
                userprofile = (from o in ctx.UserProfiles orderby o.UserId where o.UserName == model.UserName && o.Blocked==false select o).ToList().FirstOrDefault();
            }
            if (userprofile == null)
            {
                ModelState.AddModelError("", "You have been blocked.");
            }
            else
            {

                if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
                {
                    return RedirectToLocal(returnUrl);
                }

                // If we got this far, something failed, redisplay form
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }
            return View(model);
        }
Ejemplo n.º 11
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (CanteenContext db = new CanteenContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }