Пример #1
0
        public ActionResult Create([Bind(Include = "Id,MedicineCode,MedicineName,Price,ManufactureDate,ExpiryDate,CompanyName,Quantity")] Medicine medicine)
        {
            if (ModelState.IsValid)
            {
                db.Patients.Add(medicine);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(medicine));
        }
        public ActionResult Buy(Purchase p)
        {
            ApplicationDbContext dbContext = new ApplicationDbContext();

            int amount = 0, total = 0, qty = 0;

            qty      = p.Quantity;
            p.UserId = 0;
            p.Date   = DateTime.Now;
            amount   = db.Medicines.Where(e => e.MedicineName == p.MedicineName).Select(e => e.Price).FirstOrDefault();
            total    = p.Quantity * amount;
            p.Amount = total;
            Medicine data = db.Medicines.Where(e => e.MedicineName == p.MedicineName).FirstOrDefault();

            if (data != null)
            {
                data.Stock = data.Stock - qty;
                db.SaveChanges();
            }

            hc.BaseAddress = new Uri("https://localhost:44398/api/Purchases/");
            var consume = hc.PostAsJsonAsync("PostPurchase", p);

            consume.Wait();
            var test = consume.Result;

            if (test.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Пример #3
0
 public IHttpActionResult Delete(int id)
 {
     using (MedicineDBContext context = new MedicineDBContext())
     {
         Medicine m = context.Medicines.FirstOrDefault(e => e.Id == id);
         context.Medicines.Remove(m);
         context.SaveChanges();
         return(Ok());
     }
 }
        public IHttpActionResult PostPurchase(Purchase purchase)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Purchases.Add(purchase);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = purchase.Id }, purchase));
        }
Пример #5
0
        public IHttpActionResult Post(Medicine m)
        {
            using (MedicineDBContext context = new MedicineDBContext())
            {
                context.Medicines.Add(new Medicine()
                {
                    MedicineName = m.MedicineName,
                    Stock        = m.Stock,
                    Price        = m.Price
                });

                context.SaveChanges();
                //var data = context.Medicines.ToList();
            }
            return(Ok());
        }
Пример #6
0
        public IHttpActionResult Put(Medicine m)
        {
            using (MedicineDBContext context = new MedicineDBContext())
            {
                Medicine data = context.Medicines.Where(e => e.Id == m.Id).FirstOrDefault <Medicine>();

                if (data != null)
                {
                    data.MedicineName = m.MedicineName;
                    data.Stock        = m.Stock;
                    data.Price        = m.Price;
                    context.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }

                return(Ok());
            }
        }