예제 #1
0
 public ActionResult AddModify(MedicineMaster mm)
 {
     using (HISDBEntities db = new HISDBEntities())
     {
         if (mm.MMID == 0)
         {
             //AddSupplierCategories(mm);
             db.MedicineMasters.Add(mm);
             MedicineInventory mi = new MedicineInventory();
             mi.MedicineID   = mm.MMID;
             mi.AvailableQty = 0;
             db.MedicineInventories.Add(mi);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             //AddSupplierCategories(mm);
             var mi = db.MedicineInventories.Where(m => m.MedicineID == mm.MMID).FirstOrDefault();
             if (mi != null)
             {
                 mi.PricePerItem = mm.ItemPrice;
                 mi.AvailableQty = mm.AvailableQuantity;
             }
             db.Entry(mi).State = EntityState.Modified;
             db.Entry(mm).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
예제 #2
0
 public void Delete(MedicineMaster entity)
 {
     try
     {
         entities.MedicineMasters.Remove(entity);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #3
0
 public void Add(MedicineMaster entity)
 {
     try
     {
         entities.MedicineMasters.Add(entity);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #4
0
        private void AddSupplierCategories(MedicineMaster mm)
        {
            if (mm != null && mm.SupplierID == 0 && !string.IsNullOrEmpty(mm.SupplierName))
            {
                mm.SupplierID = AddSuppliers(mm.SupplierName);
            }

            if (mm.SubCategoryID == 0 && !string.IsNullOrEmpty(mm.SubCategory))
            {
                mm.SubCategoryID = AddSubCategories(mm.SubCategory);
            }
        }
예제 #5
0
 public void Attach(MedicineMaster entity)
 {
     try
     {
         entities.MedicineMasters.Attach(entity);
         entities.Entry(entity).State = EntityState.Modified;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #6
0
        public void Save(MedicineMaster entity)
        {
            try
            {
                MedicineMaster medicineMaster = entities.MedicineMasters
                                                .Where(x => x.FarmID == entity.FarmID && x.MedicineCode == entity.MedicineCode).FirstOrDefault();

                if (medicineMaster != null)
                {
                    entities.Entry(medicineMaster).State = EntityState.Modified;
                }
                else
                {
                    Add(entity);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #7
0
        public IHttpActionResult GetMedicineMaster(int MedicineCode)
        {
            try
            {
                MedicineMaster medicineMaster = new MedicineMaster();
                using (UnitOfWork uow = new UnitOfWork())
                {
                    medicineMaster = uow.MedicineMasterRepository.Get(x => x.MedicineCode == MedicineCode && x.FarmID == FARMID);

                    medicineMaster = medicineMaster == null ? new MedicineMaster {
                        MedicineCode = -1
                    } : medicineMaster;
                    return(Ok(new
                    {
                        medicineMaster
                    }));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #8
0
        //Get contact by ID
        public MedicineMaster GetMedicine(int mmID)
        {
            MedicineMaster medicineMaster = null;

            using (HISDBEntities dc = new HISDBEntities())
            {
                var v = (from med in dc.MedicineMasters
                         join mi in dc.MedicineInventories on med.MMID equals mi.MedicineID
                         join b in dc.Brands on med.BrandID equals b.BrandID
                         join bc in dc.BrandCategories on med.BrandCategoryID equals bc.CategoryID
                         join sp in dc.Suppliers on med.SupplierID equals sp.SupplierID into sup
                         from sp in sup.DefaultIfEmpty()
                         join bsc in dc.BrandSubCategories on med.SubCategoryID equals bsc.SubCategoryID into subcat
                         from bsc in subcat.DefaultIfEmpty()
                         where med.MMID.Equals(mmID)
                         select new
                {
                    med,
                    b.BrandName,
                    bc.Category,
                    sp.SupplierName,
                    bsc.SubCategory,
                    mi
                }).FirstOrDefault();
                if (v != null)
                {
                    medicineMaster                   = v.med;
                    medicineMaster.BrandName         = v.BrandName;
                    medicineMaster.Category          = v.Category;
                    medicineMaster.SubCategory       = v.SubCategory;
                    medicineMaster.SupplierName      = v.SupplierName;
                    medicineMaster.AvailableQuantity = v.mi.AvailableQty.HasValue ? v.mi.AvailableQty.Value : 0;
                    medicineMaster.ItemPrice         = v.mi.PricePerItem;
                }
                return(medicineMaster);
            }
        }
예제 #9
0
 private void UpdateMedInventory(MedicineMaster mm)
 {
     using (HISDBEntities db = new HISDBEntities())
     {
     }
 }
예제 #10
0
        public IHttpActionResult Save(MedicineMaster medicineMasterVm)
        {
            try
            {
                MedicineMaster medicineMasterDtl = new MedicineMaster();

                using (UnitOfWork uow = new UnitOfWork())
                {
                    if (medicineMasterVm.MedicineCode == -1)
                    {
                        medicineMasterDtl           = new MedicineMaster();
                        medicineMasterDtl.CreatedBy = "ADMIN";
                        medicineMasterDtl.CreatedOn = DateTime.UtcNow;
                    }
                    else
                    {
                        medicineMasterDtl = uow.MedicineMasterRepository.Get(x => x.MedicineCode == medicineMasterVm.MedicineCode);

                        medicineMasterDtl.ModifiedBy = "ADMIN";
                        medicineMasterDtl.ModifiedOn = DateTime.UtcNow;
                    }

                    medicineMasterDtl.FarmID          = FARMID;
                    medicineMasterDtl.MedicineName    = medicineMasterVm.MedicineName;
                    medicineMasterDtl.MedicineType    = medicineMasterVm.MedicineType;
                    medicineMasterDtl.MedicineCompany = medicineMasterVm.MedicineCompany;
                    medicineMasterDtl.PurchaseDate    = medicineMasterVm.PurchaseDate;
                    medicineMasterDtl.ExpiryDate      = medicineMasterVm.ExpiryDate;
                    medicineMasterDtl.BatchNo         = medicineMasterVm.BatchNo;
                    medicineMasterDtl.Supplier        = medicineMasterVm.Supplier;
                    medicineMasterDtl.Quantity        = medicineMasterVm.Quantity;
                    medicineMasterDtl.IsDeleted       = medicineMasterVm.IsDeleted;

                    //var myfilename = string.Format(@"{0}{1}", Guid.NewGuid(), ".jpeg");
                    //if (medicineMasterVm.FileName != null && medicineMasterVm.FileName.Length > 0)
                    //{
                    //    medicineMasterDtl.Photo = myfilename;
                    //}

                    uow.MedicineMasterRepository.Save(medicineMasterDtl);
                    uow.SaveChanges();

                    //if (medicineMasterVm.FileName != null && medicineMasterVm.FileName.Length > 0)
                    //{
                    //    string path = System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads/" + medicineMaster.FarmID + "/MedicineMaster/" + medicineMaster.MedicineCode + "/");
                    //    if (!Directory.Exists(path))
                    //    {
                    //        Directory.CreateDirectory(path);
                    //    }
                    //    string filepath = path + myfilename;
                    //    var bytess = Convert.FromBase64String(medicineMasterVm.FileName);
                    //    using (var imageFile = new FileStream(filepath, FileMode.Create))
                    //    {
                    //        imageFile.Write(bytess, 0, bytess.Length);
                    //        imageFile.Flush();
                    //    }
                    //}


                    return(Ok(new
                    {
                    }));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }