public ActionResult UpdateOrder(int?ID, string str)
        {
            CASDatabaseEntities db          = new CASDatabaseEntities();
            PatientOrderModel   dt          = new PatientOrderModel();
            PatientOrderDetail  objOrder    = new PatientOrderDetail();
            DrugDelivery        objDelivery = new DrugDelivery();

            var id      = Convert.ToInt32(ID);
            var getData = db.PatientOrderDetails.Where(m => m.PatientOrderID == id).FirstOrDefault();

            if (str == "Deliver")
            {
                getData.OrderStatus = "Delivered";

                objDelivery.PatientOrderID = getData.PatientOrderID;
                objDelivery.DeliveryDate   = DateTime.Today;
                db.DrugDeliveries.Add(objDelivery);

                Session["Deliver"] = "Delivered";
            }
            else
            {
                getData.OrderStatus = "Rejected";
            }
            dt.OrderStatus = getData.OrderStatus;
            db.SaveChanges();
            return(RedirectToAction("ViewPatientOrders", "Salesperson"));
        }
예제 #2
0
        // Get (PatientOrderDetail) Patient detail (patientId)
        public PatientOrderDetail GetPatientDetail(int patientId)
        {
            var model     = new PatientOrderDetail();
            var patient   = db.TM_Users.Find(patientId);
            var patDetail = db.TM_Patient.Where(p => p.UserId == patientId).FirstOrDefault();
            var address   = db.UserAddresses.Where(ua => ua.UserId == patientId)
                            .Join(
                db.TM_Address,                  // first table
                u => u.AddressId,               // first key
                a => a.Id,
                (u, a) => new { a.Id, a.Address, a.WardId }
                ).FirstOrDefault();

            model.PatienId      = patientId;
            model.PatientName   = patient.FullName;
            model.Avatar        = patient.Avatar;
            model.PhoneNumber   = patient.PhoneNumber;
            model.Gender        = patient.Gender == "M" ? "Nam" : patient.Gender == "F" ? "Nữ" : "Khác";
            model.Email         = patient.Email;
            model.LastLogin     = patient.LastLogin;
            model.Age           = patient.DateOfBirth == null ? 0 : DateTime.Now.Year - patient.DateOfBirth.Value.Year;
            model.Address       = address == null?null:ToFullAddress((int)address.WardId, address.Address);
            model.AssurenceCard = patDetail.AssuranceCard;
            model.IdentityCard  = patDetail.IdentityCard;
            model.Orders        = ListOrdersByPatient(patientId);
            return(model);
        }
예제 #3
0
        public ActionResult OrderDrug(OrderModel od)
        {
            ClASDBEntities     db  = new ClASDBEntities();
            PatientOrderDetail pod = new PatientOrderDetail();


            List <SelectListItem> listD = new List <SelectListItem>();
            var getdata = (from d in db.Drugs where d.IsDeleted == "No" select new { d.DrugID, d.DrugName }).ToList();

            foreach (var item in getdata)
            {
                listD.Add(new SelectListItem
                {
                    Text  = item.DrugName,
                    Value = Convert.ToString(item.DrugID)
                });
            }
            od.ListDrug = listD;
            Random r = new Random();

            var patId   = Convert.ToInt32(Session["ID"]);
            var getd    = db.Drugs.Where(m => m.DrugID == od.DrugId).FirstOrDefault();
            var getQtty = getd.TotalQuantityAvailable;

            //od.TotalQtty = getQtty;
            if (ModelState.IsValid)
            {
                if (od.OrderQtty == 0)
                {
                    ViewBag.text = "Enter order quantity more than 0!";
                }
                else if (od.OrderQtty <= getQtty)
                {
                    //getd.TotalQuantityAvailable = getQtty - od.OrderQtty;
                    ViewBag.text    = "Placing Order...";
                    pod.DrugId      = od.DrugId;
                    pod.OrderStatus = "Requested";
                    pod.PatientID   = patId;
                    pod.Quantity    = od.OrderQtty;
                    pod.OrderNumber = r.Next(1, 1000);
                    pod.OrderDate   = DateTime.Now;
                    db.PatientOrderDetails.Add(pod);
                    db.SaveChanges();
                }
                else
                {
                    ViewBag.text = "Enter order quantity less than available quantity!";
                }
                ViewBag.text2 = "Order Placed!";
            }
            else
            {
                ViewBag.text2 = "Error Occurred!";
            }
            return(View(od));
        }
예제 #4
0
        public ActionResult OrderDrug(DrugModel dm)
        {
            Clinic_automation_systemEntities db = new Clinic_automation_systemEntities();
            var getqty             = db.Drugs.Where(m => m.DrugId == dm.DrugId).FirstOrDefault();
            int id                 = Convert.ToInt32(Session["MemberId"]);
            var getpid             = db.Patients.Where(m => m.MemberId == id).FirstOrDefault();
            int month              = DateTime.Now.Month;
            PatientOrderDetail obj = new PatientOrderDetail();

            if (dm.OrderQuantity < getqty.TotalQuantityAvailable)
            {
                obj.PatientId   = getpid.PatientId;
                obj.DrugId      = dm.DrugId;
                obj.OrderDate   = DateTime.Now;
                obj.Quantity    = dm.OrderQuantity;
                obj.OrderStatus = "Requested";
                db.PatientOrderDetails.Add(obj);
                getqty.TotalQuantityAvailable = getqty.TotalQuantityAvailable - dm.OrderQuantity;
                db.SaveChanges();
                ViewBag.text = "Order placed successfully";
            }
            else
            {
                ViewBag.text = "Order Quantity cannot exceed Total Quantity";
            }

            var getdata = db.Drugs.Where(m => m.IsDeleted == false).ToList();

            List <SelectListItem> lst = new List <SelectListItem>();

            if (getdata != null)
            {
                foreach (var item in getdata)
                {
                    lst.Add(new SelectListItem
                    {
                        Text  = item.DrugName,
                        Value = item.DrugId.ToString()
                    });
                }
                dm.DrugNameList = lst;
            }
            return(View(dm));
        }
        public ActionResult OrderDrugs(PatientOrderModel dt)
        {
            CASDatabaseEntities db       = new CASDatabaseEntities();
            PatientOrderDetail  objOrder = new PatientOrderDetail();

            Random random = new Random();

            List <SelectListItem> list = new List <SelectListItem>();
            var getDrugDetails         = from d in db.Drugs
                                         where d.IsDeleted == false
                                         select new
            {
                d.DrugID,
                d.DrugName,
            };

            foreach (var item in getDrugDetails)
            {
                list.Add(new SelectListItem
                {
                    Text  = item.DrugName,
                    Value = item.DrugID.ToString()
                });
            }
            dt.ListDrug = list;

            var getQuantity = db.Drugs.Where(m => m.DrugID == dt.DrugID).FirstOrDefault();

            dt.QuantityAvailable = getQuantity.QOH;
            dt.QuantityType      = getQuantity.QOHType;
            dt.DrugID            = getQuantity.DrugID;

            var getSales = db.Salespersons.SingleOrDefault();

            dt.SalespersonID = getSales.SalespersonID;

            if (ModelState.IsValid)
            {
                if (dt.Quantity == 0)
                {
                    ViewBag.text = "Quantity Must Not be Zero.";
                }
                else if (dt.Quantity <= dt.QuantityAvailable)
                {
                    objOrder.DrugID        = dt.DrugID;
                    objOrder.Quantity      = dt.Quantity;
                    objOrder.OrderNumber   = random.Next();
                    objOrder.OrderDate     = DateTime.Today;
                    objOrder.OrderStatus   = "Requested";
                    objOrder.PatientID     = Convert.ToInt32(Session["ID"]);
                    objOrder.SalespersonID = dt.SalespersonID;

                    db.PatientOrderDetails.Add(objOrder);

                    getQuantity.QOH -= dt.Quantity;
                    if (getQuantity.QOH == 0)
                    {
                        getQuantity.IsDeleted = true;
                    }
                    db.SaveChanges();
                    ViewBag.text = "Order Successfully Placed";
                }
                else if (dt.Quantity > dt.QuantityAvailable)
                {
                    ViewBag.text = "Quantity Exceeded";
                }
            }
            return(View(dt));
        }