示例#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
                });
            }
        }
 //
 // GET: /Product/
 /// <summary>
 /// Get the index for the products page
 /// /Product/
 /// </summary>
 /// <returns>View for the product index</returns>
 public ActionResult Index()
 {
     var products = new ProductRepository().GetAll();
     return View(products);
 }
 /// <summary>
 /// Get the details for a product
 /// </summary>
 /// <param name="id">id of product to get details for</param>
 /// <returns></returns>
 public ActionResult Details(int id)
 {
     var product = new ProductRepository().Get(id);
     return View(product);
 }
示例#5
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
                });
            }
        }
示例#6
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
                });
            }
        }
示例#7
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
         });
     }
 }
示例#8
0
        /// <summary>
        /// Add product to the system
        /// </summary>
        /// <returns>Result of the add</returns>
        public JsonResult AddProduct()
        {
            try
            {
                CategoryRepository categoryRepo = new CategoryRepository();
                ProductRepository productRepo = new ProductRepository();

                Product product = new Product();
                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"]);
                product.QuantityOnHand = int.Parse(Request.Form["QuantityOnHand"]);
                product.Counter = 0;
                product.IsActive = true;

                productRepo.Add(product);

                return Json(new
                {
                    error = false,
                    Name = product.Name,
                    Id = product.Id
                });
            }
            catch
            {
                return Json(new
                {
                    error = true
                });
            }
        }