private void UpdateCustomerMain(PharmacyDbContext db)
        {
            SaleMain main =
                db.SaleMain.Where(a => a.CustomerId == _customerId).OrderByDescending(x => x.Id).FirstOrDefault();

            main.DuePaid        += Convert.ToDecimal(txtDuePay.Text);
            db.Entry(main).State = EntityState.Modified;
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,Name,Code,AvailableQuantity")] Medicine medicine)
 {
     if (ModelState.IsValid)
     {
         db.Entry(medicine).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(medicine));
 }
        public RackViewModel UpdateRack(RackViewModel model)
        {
            var result = new PHRMRackModel()
            {
                RackId      = model.RackId,
                Name        = model.Name,
                Description = model.Description,
                CreatedBy   = model.CreatedBy,
                CreatedOn   = model.CreatedOn
            };

            db.Entry(result).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(model);
        }
Ejemplo n.º 4
0
        public ActionResult Edit([Bind(Include = "Id,Address,FirstName,LastName,EGN")] Person person)
        {
            var found = db.Persons.Where(f => f.EGN == person.EGN && f.Id != person.Id).FirstOrDefault();

            if (found != null)
            {
                ModelState.AddModelError("EGN", "EGN already exists!!!");
            }

            if (ModelState.IsValid)
            {
                db.Entry(person).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(person));
        }
Ejemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "Id,Number,DoneAt,CounterpartyId")] Sell sell)
        {
            var found = db.Sells.Where(s => s.Number == sell.Number && s.Id != sell.Id).FirstOrDefault();

            if (found != null)
            {
                ModelState.AddModelError("Number", "Number already exists in different sell!!!");
            }

            if (ModelState.IsValid)
            {
                db.Entry(sell).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CounterpartyId = new SelectList(db.Counterparties, "Id", "Stringed", sell.CounterpartyId);
            return(View(sell));
        }
Ejemplo n.º 6
0
        public ActionResult Edit([Bind(Include = "Id,Price,Quantity,MedicineId,SellId")] SoldMedicine soldMedicine)
        {
            var found = db.Medicines.Find(soldMedicine.MedicineId).AvailableQuantity - soldMedicine.Quantity;

            if (found < 0)
            {
                ModelState.AddModelError("Quantity", "Quantity too low!!!");
            }

            if (ModelState.IsValid)
            {
                db.Entry(soldMedicine).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.MedicineId = new SelectList(db.Medicines, "Id", "Name", soldMedicine.MedicineId);
            ViewBag.SellId     = new SelectList(db.Sells, "Id", "Number", soldMedicine.SellId);
            return(View(soldMedicine));
        }
Ejemplo n.º 7
0
        public ActionResult Edit([Bind(Include = "Id,Address,Name,Code,EIK")] Firm firm)
        {
            var found = db.Firms.Where(f => f.EIK == firm.EIK && f.Id != firm.Id).FirstOrDefault();

            if (found != null)
            {
                ModelState.AddModelError("EIK", "EIK already exists!!!");
            }

            if (!this.IsRealEIK(firm.EIK))
            {
                ModelState.AddModelError("EIK", "EIK is fake!!!");
            }

            if (ModelState.IsValid)
            {
                db.Entry(firm).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(firm));
        }
        public ActionResult Edit([Bind(Include = "Id,Price,Quantity,MedicineId,DeliveryId")] DeliveredMedicine deliveredMedicine)
        {
            var error = string.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(deliveredMedicine).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateException ex)
                {
                    error = ex.GetDeepestMessage();
                }
            }

            ViewBag.DeliveryId = new SelectList(db.Deliveries, "Id", "Number", deliveredMedicine.DeliveryId);
            ViewBag.MedicineId = new SelectList(db.Medicines, "Id", "Name", deliveredMedicine.MedicineId);
            ViewBag.Error      = error;

            return(View(deliveredMedicine));
        }
 public static Boolean StockTransferToPharmacy(List <WARDStockModel> stkTransfer, WardSupplyDbContext wardSupplyDbContext, PharmacyDbContext pharmacyDbContext, RbacUser currentUser)
 {
     //Transaction Begins
     using (var dbContextTransaction = wardSupplyDbContext.Database.BeginTransaction())
     {
         try
         {
             if (stkTransfer != null)
             {
                 for (int i = 0; i < stkTransfer.Count; i++)
                 {
                     var            stockId      = stkTransfer[i].StockId;
                     WARDStockModel updatedStock = (from stock in wardSupplyDbContext.WARDStockModel
                                                    where stock.StockId == stockId
                                                    select stock
                                                    ).FirstOrDefault();
                     updatedStock.AvailableQuantity = (int)(Convert.ToDecimal(stkTransfer[i].AvailableQuantity)) - (int)(Convert.ToDecimal(stkTransfer[i].DispachedQuantity));
                     wardSupplyDbContext.Entry(updatedStock).Property(a => a.AvailableQuantity).IsModified = true;
                     //transaction table
                     var selectedstockTxnItm = new WARDTransactionModel();
                     selectedstockTxnItm.WardId          = updatedStock.WardId;
                     selectedstockTxnItm.ItemId          = updatedStock.ItemId;
                     selectedstockTxnItm.StockId         = updatedStock.StockId;
                     selectedstockTxnItm.TransactionId   = 0;
                     selectedstockTxnItm.Quantity        = (int)(Convert.ToDecimal(stkTransfer[i].DispachedQuantity));
                     selectedstockTxnItm.TransactionType = "WardToPharmacy";
                     selectedstockTxnItm.Remarks         = "Sent From Ward To Pharmacy";
                     selectedstockTxnItm.CreatedBy       = currentUser.UserName;
                     selectedstockTxnItm.CreatedOn       = DateTime.Now;
                     selectedstockTxnItm.IsWard          = true;
                     wardSupplyDbContext.TransactionModel.Add(selectedstockTxnItm);
                     wardSupplyDbContext.SaveChanges();
                     //pharmacy stock changes
                     var            itemId  = stkTransfer[i].ItemId;
                     var            batchNo = stkTransfer[i].BatchNo;
                     PHRMStockModel updatedPharmacyStock = (from stock in pharmacyDbContext.PHRMStock
                                                            where stock.ItemId == itemId && stock.BatchNo == batchNo
                                                            select stock
                                                            ).FirstOrDefault();
                     updatedPharmacyStock.AvailableQuantity = (int)(Convert.ToDecimal(updatedPharmacyStock.AvailableQuantity)) + (int)(Convert.ToDecimal(stkTransfer[i].DispachedQuantity));
                     pharmacyDbContext.Entry(updatedPharmacyStock).Property(a => a.AvailableQuantity).IsModified = true;
                     //Pharmacy Transaction Table
                     var phrmStockTxn = new PHRMStockTransactionItemsModel();
                     phrmStockTxn.ItemId             = updatedPharmacyStock.ItemId;
                     phrmStockTxn.BatchNo            = updatedPharmacyStock.BatchNo;
                     phrmStockTxn.ExpiryDate         = stkTransfer[i].ExpiryDate;
                     phrmStockTxn.Quantity           = (int)(Convert.ToDecimal(stkTransfer[i].DispachedQuantity));
                     phrmStockTxn.FreeQuantity       = 0;
                     phrmStockTxn.Price              = (int)(Convert.ToDecimal(stkTransfer[i].MRP));
                     phrmStockTxn.DiscountPercentage = 0;
                     phrmStockTxn.VATPercentage      = 0;
                     phrmStockTxn.SubTotal           = (int)(Convert.ToDecimal(phrmStockTxn.Quantity)) * (int)(Convert.ToDecimal(phrmStockTxn.Price));
                     phrmStockTxn.TotalAmount        = phrmStockTxn.SubTotal;
                     phrmStockTxn.InOut              = "in";
                     phrmStockTxn.CreatedBy          = currentUser.UserId;
                     phrmStockTxn.CreatedOn          = DateTime.Now;
                     phrmStockTxn.MRP             = phrmStockTxn.Price;
                     phrmStockTxn.TransactionType = "WardToPharmacy";
                     pharmacyDbContext.PHRMStockTransactionModel.Add(phrmStockTxn);
                     pharmacyDbContext.SaveChanges();
                 }
             }
             dbContextTransaction.Commit();
             return(true);
         }
         catch (Exception ex)
         {
             dbContextTransaction.Rollback();
             throw ex;
         }
     }
 }