示例#1
0
 public JsonResult AddInventory()
 {
     try
     {
         ProductRepository productRepo = new ProductRepository();
         Product product = productRepo.Get(int.Parse(Request.Form["Product"]));
         product.QuantityOnHand += int.Parse(Request.Form["Quantity"]);
         return Json(new
         {
             error = "false"
         });
     }
     catch
     {
         return Json(new
         {
             error = "true"
         });
     }
 }
        /// <summary>
        /// Add an item to the patient's invoice.
        /// </summary>
        /// <returns>The Jason object so it can be immediately displayed.</returns>
        public JsonResult AddInvoiceItem()
        {
            try
            {
                //Build Line Item objects
                InvoiceItem lineItem = new InvoiceItem();

                //Get patient object
                int patientID = int.Parse(Request.Form["patientID"]);
                PatientRepository patientRepo = new PatientRepository();
                var patient = patientRepo.Get(patientID);

                //Get current open patient checkin
                var query = from checkin in patient.PatientCheckIns
                            where checkin.CheckOutTime == DateTime.MinValue
                            select checkin;
                PatientCheckIn openCheckIn = query.First<PatientCheckIn>();

                //Invoice Repository
                InvoiceRepository invoiceRepo = new InvoiceRepository();

                //Product Repository
                ProductRepository productRepo = new ProductRepository();

                //Service Repository
                ServiceRepository serviceRepo = new ServiceRepository();

                //Quantity
                if (Request.Form["quantity"] != "")
                {
                    lineItem.Quantity = int.Parse(Request.Form["quantity"]);
                    lineItem.Invoice = openCheckIn.Invoice;
                    lineItem.IsActive = true;

                    //Product
                    if (Request.Form["product"] != "")
                    {
                        lineItem.Product = productRepo.Get(int.Parse(Request.Form["product"]));
                        lineItem.Service = null;
                        invoiceRepo.AddLineItem(lineItem);
                        UnitOfWork.CurrentSession.Flush();
                        return Json(new
                        {
                            error = "false",
                            lineItem.Product.Name,
                            lineItem.Quantity

                        });
                    } //Service
                    else if (Request.Form["service"] != "")
                    {
                        lineItem.Service = serviceRepo.Get(int.Parse(Request.Form["service"]));
                        lineItem.Product = null;
                        invoiceRepo.AddLineItem(lineItem);
                        UnitOfWork.CurrentSession.Flush();
                        return Json(new
                        {
                            error = "false",
                            lineItem.Service.Name,
                            lineItem.Quantity
                        });
                    }
                }

                return Json(new
                {
                    error = "false"
                });
            }
            catch (Exception e)
            {
                return Json(new
                {
                    error = "true",
                    status = e.Message
                });
            }
        }
示例#3
0
        /// <summary>
        /// Remove product from the system
        /// </summary>
        /// <returns>result of the delete</returns>
        public JsonResult RemoveProduct()
        {
            try
            {
                ProductRepository productRepo = new ProductRepository();
                Product product = productRepo.Get(int.Parse(Request.Form["ProductId"]));
                product.IsActive = false;
                UnitOfWork.CurrentSession.Flush();

                return Json(new
                {
                    error = false
                });
            }
            catch
            {
                return Json(new
                {
                    error = true
                });
            }
        }
示例#4
0
        /// <summary>
        /// Generates a list of products
        /// </summary>
        /// <returns></returns>
        public JsonResult ProductList()
        {
            try
            {
                int productID = int.Parse(Request.Form["ID"]);
                ProductRepository productRepo = new ProductRepository();
                var product = productRepo.Get(productID);

                var resultSet = new List<object>();
                var jsonResult = new JsonResult();

                resultSet.Add(new
                {
                    error = false,
                    Name = product.Name,
                    Unit = product.Unit,
                    Category = product.Category.Name,
                    Price = product.Price,
                    Quantity = product.QuantityOnHand
                });

                jsonResult.Data = resultSet;

                return jsonResult;
            }
            catch (Exception)
            {

                return Json(new
                {
                    error = true
                });
            }
        }
示例#5
0
 /// <summary>
 /// Edit a product and return results
 /// </summary>
 /// <returns>Result of the update</returns>
 public JsonResult EditProduct()
 {
     try
     {
         ProductRepository productRepo = new ProductRepository();
         CategoryRepository categoryRepo = new CategoryRepository();
         Product product = productRepo.Get(int.Parse(Request.Form["ProductId"]));
         product.Name = Request.Form["Name"];
         product.Unit = Request.Form["Unit"];
         product.Category = categoryRepo.Get(int.Parse(Request.Form["CategoryId"]));
         product.Price = decimal.Parse(Request.Form["Price"]);
         return Json(new
         {
             error = false
         });
     }
     catch
     {
         return Json(new
         {
             error = true
         });
     }
 }