public ActionResult paymentOrderIn(int id)
        {
            //check if user is login in App
            string username = User.Identity.Name;

            if (string.IsNullOrEmpty(username))
            {
                return(RedirectToAction("login", "Account"));
            }
            // Declare productVM
            OrderInVM model;

            using (Db db = new Db())
            {
                // Get the OrderIn
                OrderInDTO dto = db.OrderIn.Find(id);

                // Make sure OrderIn exists
                if (dto == null)
                {
                    return(Content("هذا الفاتورة  غير موجودة "));
                }

                // init model
                model = new OrderInVM(dto);
            }

            // Return view with model
            return(View(model));
        }
        public long AddOrderIn()
        {
            long id;

            using (Db db = new Db())
            {
                // Get the Medicine
                var dto = db.OrderIn.Select(x => x.Id);
                // Make sure OrderOut exists
                if (dto == null)
                {
                    id = 1;
                }
                else
                {
                    id = dto.Max() + 1;
                }
                // Create OrderInDTO
                OrderInDTO orderInDTO = new OrderInDTO()
                {
                    OrderDate = DateTime.Now,
                    OrderId   = id
                };
                // Add the DTO
                db.OrderIn.Add(orderInDTO);
                // Save
                db.SaveChanges();
            }
            return(id);
        }
Пример #3
0
 public OrderInVM(OrderInDTO row)
 {
     this.Id             = row.Id;
     this.OrderId        = row.OrderId;
     this.TotalePrice    = row.TotalePrice;
     this.TotaleQuantity = row.TotaleQuantity;
     this.PaidPrice      = row.PaidPrice;
     this.UnpaidPrice    = row.UnpaidPrice;
     this.OrderDate      = row.OrderDate;
     this.PayementDate   = row.PayementDate;
 }
        public ActionResult printOrderInfo(int id)
        {
            List <OrderInDetialsVM> listOrderInDetials;
            OrderInVM model;

            using (Db db = new Db())
            {
                listOrderInDetials = db.OrderInDetials.Where(x => x.OrderId == id)
                                     .ToArray().Select(x => new OrderInDetialsVM(x)).ToList();
                OrderInDTO dto = db.OrderIn.Find(id);
                model = new OrderInVM(dto);
            }
            ViewBag.OrderDate    = model.OrderDate;
            ViewBag.Paidprice    = model.PaidPrice;
            ViewBag.Unpaidprice  = model.UnpaidPrice;
            ViewBag.payementDate = model.PayementDate.ToShortDateString();

            return(View(listOrderInDetials));
        }
        public ActionResult paymentOrderIn(OrderInVM model)
        {
            // Get OrderIn id
            long id = model.Id;

            // Check model state

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "لم تتم عملية التعديل  ");
                return(View(model));
            }
            if (model.PaidPrice > model.UnpaidPrice)
            {
                ModelState.AddModelError("", "المبلغ الدخل أكثر من المبلغ المتبقي");
                return(View(model));
            }
            else
            {
                // Update OrdrIn
                using (Db db = new Db())
                {
                    OrderInDTO dto = db.OrderIn.Find(id);
                    dto.PaidPrice  += model.PaidPrice;
                    dto.UnpaidPrice = dto.TotalePrice - dto.PaidPrice;

                    if (model.TotalePrice == model.PaidPrice)
                    {
                        dto.PayementDate = DateTime.Now.Date;
                    }
                    db.SaveChanges();
                }

                // Set TempData message
                TempData["SM"] = "تم عملية السداد  بنجاح ";
            }
            // Redirect
            return(RedirectToAction("paymentOrderIn"));
        }
        public void saveOrderIn(int order_id, int Medicine_Quantity, int orderPrice, int Paid_Price, DateTime PayementDate)
        {
            // Update Medicine
            using (Db db = new Db())
            {
                OrderInDTO dto = db.OrderIn.Find(order_id);


                dto.TotalePrice    = orderPrice;
                dto.TotaleQuantity = Medicine_Quantity;
                dto.PaidPrice      = Paid_Price;
                dto.UnpaidPrice    = orderPrice - Paid_Price;
                if (Paid_Price == orderPrice)
                {
                    dto.PayementDate = DateTime.Now.Date;
                }
                else
                {
                    dto.PayementDate = PayementDate.Date;
                }

                db.SaveChanges();
            }
        }