Exemple #1
0
        public ActionResult Edit(string id, string level)
        {
            Int32 theId = Convert.ToInt32(Models.Encript.DecryptString(id, true));
            PrimarySchoolStudent theStudent               = work.PrimarySchoolStudentRepository.GetByID(theId);
            List <Store>         theStoreItems            = work.StoreRepository.Get(a => a.Level.Equals(level)).OrderBy(a => a.ItemName).ToList();
            List <Store>         theStoreItemWithoutClass = work.StoreRepository.Get(a => a.Level == "").OrderBy(a => a.ItemName).ToList();
            List <Store>         theItems = new List <Store>();

            foreach (var item in theStoreItems)
            {
                theItems.Add(item);
            }

            foreach (var item in theStoreItemWithoutClass)
            {
                theItems.Add(item);
            }

            StudentItemViewModel theItemViewModel = new StudentItemViewModel();

            theItemViewModel.StudentStoreItem = theItems;
            theItemViewModel.StudentID        = theStudent.UserID;
            theItemViewModel.StudentName      = theStudent.LastName;
            theItemViewModel.Level            = theStudent.PresentLevel;
            // theItemViewModel.


            return(View(theItemViewModel));
        }
Exemple #2
0
        //
        // GET: /StudentStoreItemRepository/Create

        public ActionResult Create(int?id, string level)
        {
            PrimarySchoolStudent theStudent               = work.PrimarySchoolStudentRepository.GetByID(id);
            List <Store>         theStoreItems            = work.StoreRepository.Get(a => a.Level.Equals(level)).ToList();
            List <Store>         theStoreItemWithoutClass = work.StoreRepository.Get(a => a.Level == null).ToList();
            List <Store>         theItems = new List <Store>();

            foreach (var item in theStoreItems)
            {
                theItems.Add(item);
            }

            foreach (var item in theStoreItemWithoutClass)
            {
                theItems.Add(item);
            }



            StudentItemViewModel theItemViewModel = new StudentItemViewModel();

            theItemViewModel.StudentStoreItem = theItems;
            theItemViewModel.StudentID        = theStudent.UserID;
            theItemViewModel.StudentName      = theStudent.LastName;
            theItemViewModel.Level            = theStudent.PresentLevel;
            // theItemViewModel.


            return(View(theItemViewModel));
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            student = await _context.Students.Where(d => d.Id == id).Select(d => new StudentItemViewModel
            {
                id          = d.Id,
                studentName = d.StudentName,
                age         = d.Age,
                gpa         = d.Gpa,
                classRoomId = d.ClassRoomId.Value
            }).FirstOrDefaultAsync();

            if (student == null)
            {
                return(NotFound());
            }

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id.HasValue == false)
            {
                return(NotFound());
            }

            var classRoom = await _context.ClassRooms.Where(d => d.Id == id).FirstOrDefaultAsync();

            if (classRoom == null)
            {
                return(NotFound());
            }



            student = new StudentItemViewModel
            {
                classRoomId = id.Value
            };

            return(Page());
        }
Exemple #5
0
        public ActionResult Edit(StudentItemViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Order theOrder = new Order();
                    theOrder.Term = model.Term;
                    List <Order> theLastOrder = work.OrderRepository.Get().OrderBy(a => a.OrderID).ToList();
                    if (theLastOrder.Count == 0)
                    {
                        theOrder.OrderNumber = 10000001;
                    }
                    else
                    {
                        theOrder.OrderNumber = theLastOrder.Last().OrderNumber + 1;
                    }
                    theOrder.StudentLastName = model.StudentName;
                    theOrder.studentID       = model.StudentID;
                    theOrder.OrderDate       = DateTime.Now;
                    // theOrder.
                    int Quantity = 0;
                    //  decimal TotalAmount = 0;

                    foreach (var theitem in model.StudentStoreItem)
                    {
                        Quantity = theitem.QuantityNeeded + Quantity;
                        // TotalAmount = (theitem.QuantityNeeded * theitem.Amount) + TotalAmount;
                    }

                    theOrder.ItemQuantity = Quantity;
                    theOrder.TotalAmount  = model.TotalCost;
                    theOrder.Level        = model.Level;

                    work.OrderRepository.Insert(theOrder);
                    // work.Save();

                    foreach (var theitem in model.StudentStoreItem)
                    {
                        if (theitem.QuantityNeeded != 0)
                        {
                            Store theStoreItem = work.StoreRepository.GetByID(theitem.StoreID);

                            if (theStoreItem.Quanity < theitem.QuantityNeeded)
                            {
                                ModelState.AddModelError("", "Quantity Requested Most be Less than Quantity in Store");
                                return(View(model));
                            }

                            int availableQuanity = theStoreItem.Quanity;
                            theStoreItem.Quanity = availableQuanity - theitem.QuantityNeeded;
                            work.StoreRepository.Update(theStoreItem);
                            OrderItem theOrderItem = new OrderItem();
                            theOrderItem.Quantity    = theitem.QuantityNeeded;
                            theOrderItem.SubTotal    = theitem.QuantityNeeded * theitem.Amount;
                            theOrderItem.ItemName    = theitem.ItemName;
                            theOrderItem.OrderID     = theOrder.OrderID;
                            theOrderItem.OrderNumber = theOrder.OrderNumber;
                            work.OrderItemRepository.Insert(theOrderItem);
                            work.Save();
                        }
                    }
                }
                work.Save();
                // TODO: Add insert logic here
                return(RedirectToAction("Index", "Order"));
                // return RedirectToAction("Index");
            }
            catch
            {
                return(View(model));
            }
        }
Exemple #6
0
        public ActionResult Create(StudentItemViewModel model)
        {
            try
            {
                int     quantity    = 0;
                decimal totalAmount = 0;
                if (ModelState.IsValid)
                {
                    Order        theOrder     = new Order();
                    List <Order> theLastOrder = work.OrderRepository.Get().OrderBy(a => a.OrderID).ToList();
                    if (theLastOrder.Count == 0)
                    {
                        theOrder.OrderNumber = 10000001;
                    }
                    else
                    {
                        theOrder.OrderNumber = theLastOrder.Last().OrderNumber + 1;
                    }
                    theOrder.StudentLastName = model.StudentName;
                    theOrder.studentID       = model.StudentID;
                    // theOrder.Level = model.Level;
                    theOrder.OrderDate = DateTime.Now;
                    // theOrder.
                    int     Quantity    = 0;
                    decimal TotalAmount = 0;

                    foreach (var theitem in model.StudentStoreItem)
                    {
                        Quantity    = theitem.QuantityNeeded + Quantity;
                        TotalAmount = (theitem.QuantityNeeded * theitem.Amount) + TotalAmount;
                    }

                    theOrder.ItemQuantity = Quantity;
                    theOrder.TotalAmount  = TotalAmount;
                    theOrder.Term         = model.Term;

                    quantity    = Quantity;
                    totalAmount = TotalAmount;

                    work.OrderRepository.Insert(theOrder);
                    work.Save();

                    foreach (var theitem in model.StudentStoreItem)
                    {
                        // model.to
                        OrderItem theOrderItem = new OrderItem();
                        theOrderItem.Quantity    = theitem.QuantityNeeded;
                        theOrderItem.SubTotal    = theitem.QuantityNeeded * theitem.Amount;
                        theOrderItem.ItemName    = theitem.ItemName;
                        theOrderItem.OrderID     = theOrder.OrderID;
                        theOrderItem.OrderNumber = theOrder.OrderNumber;
                        work.OrderItemRepository.Insert(theOrderItem);
                        work.Save();
                    }
                }
                if (User.Identity.Name != "5000001")
                {
                    //quantity = Quantity;
                    //totalAmount = TotalAmount;
                    AuditTrail audit = new AuditTrail {
                        Date = DateTime.Now, Action = "Item Bought by  Name:-" + model.StudentID + " " + "Quantity and Total amount:- " + quantity + " " + totalAmount, UserID = User.Identity.Name
                    };
                    work.AuditTrailRepository.Insert(audit);
                    work.Save();
                }
                work.Save();
                // TODO: Add insert logic here

                return(RedirectToAction("Index", "Order"));
            }
            catch
            {
                return(View("Edit", model));
            }
        }