public ActionResult DeleteProduct(int id)
        {
            tbl_Product      tb  = _db.tbl_Product.Where(u => u.ProductId == id).FirstOrDefault();
            ProductViewModel pvm = new ProductViewModel();

            pvm.ProductId          = tb.ProductId;
            pvm.ProductName        = tb.ProductName;
            pvm.ProductDescription = tb.ProductDescription;
            pvm.ProductPackingDate = tb.ProductPackingDate;
            pvm.ProductExpireDate  = tb.ProductExpireDate;
            tbl_Deals td = _db.tbl_Deals.Where(u => u.DealsId == id).FirstOrDefault();

            pvm.DealsName = td.DealsName;
            tbl_ProductCategory tpc = _db.tbl_ProductCategory.Where(u => u.CategoryId == tb.CategoryId).FirstOrDefault();

            pvm.CategoryName = tpc.CategoryName;
            tbl_ProductStatus tpss = _db.tbl_ProductStatus.Where(u => u.StatusId == tb.StatusId).FirstOrDefault();

            pvm.StatusName = tpss.StatusName;
            tbl_ProductStore tps = _db.tbl_ProductStore.Where(u => u.ProductId == tb.ProductId).FirstOrDefault();
            tbl_Store        ts  = _db.tbl_Store.Where(u => u.StoreId == tps.StoreId).FirstOrDefault();

            pvm.StoreName = ts.StoreName;
            return(View(pvm));
        }
示例#2
0
        /// <summary>
        /// them moi khach san
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public JsonResult CreateHotels(HotelDefaultModel hotel)
        {
            object[] message        = new object[2];
            DataSet  ds             = new DataSet();
            string   actionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string   controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();

            try
            {
                if (hotel != null & ModelState.IsValid)
                {
                    ds         = db.InsertHotel(hotel);
                    message[0] = ds.Tables[0].Rows[0].ItemArray;
                    if (ds.Tables.Count > 1)
                    {
                        message[1] = db.getObjectHotel(ds.Tables[1]);
                        tbl_Store tbl = new tbl_Store();
                        tbl.title       = "Kho chính";
                        tbl.SysHotelID  = (new HotelService()).GetHotelByCode(ds.Tables[1].Rows[0]["code"].ToString()).Id;
                        tbl.typeStore   = 1;
                        tbl.datecreated = DateTime.Now;
                        tbl.creatorid   = comm.GetUserId();
                        new StoreManagerService().InsertOrUpdateStoreGeneral(tbl);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //ViewData["hotelList"] = result;
            return(Json(new { mess = message }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteStores(int id)
        {
            tbl_Store tb = _db.tbl_Store.Where(u => u.StoreId == id).FirstOrDefault();

            _db.tbl_Store.Remove(tb);
            _db.SaveChanges();
            return(RedirectToAction("Store"));
        }
        public ActionResult EditStore(int id)
        {
            tbl_Store      tb  = _db.tbl_Store.Where(p => p.StoreId == id).FirstOrDefault();
            StoreViewModel svm = new StoreViewModel();

            svm.StoreId       = tb.StoreId;
            svm.StoreName     = tb.StoreName;
            svm.StoreLocation = tb.StoreLocation;
            svm.StoreCapacity = tb.StoreCapacity;
            return(View(svm));
        }
示例#5
0
        public ActionResult ThemKho(FormCollection collection, tbl_Store kho)
        {
            var maSP  = Request.Form["masp"];
            var slTon = collection["soluongton"];


            kho.ProductId = Convert.ToInt32(maSP);
            kho.Number    = Convert.ToInt32(slTon);

            ddd.tbl_Stores.InsertOnSubmit(kho);
            ddd.SubmitChanges();
            return(RedirectToAction("Kho", "Kho"));
        }
 public int InsertOrUpdateStoreGeneral(tbl_Store store)
 {
     try
     {
         using (var db = _connectionData.OpenDbConnection())
         {
             return((int)db.Insert(store, selectIdentity: true));
         }
     }
     catch (Exception)
     {
         return(-1);
     }
 }
示例#7
0
        /// Save Store
        public bool SaveStores(StoreViewModel storeViewModel)
        {
            bool      status = false;
            tbl_Store stores = new tbl_Store();

            Mapper.Map(storeViewModel, stores);

            stores.IsActive     = true;
            stores.CreatedDate  = DateTime.Now;
            stores.ModifiedDate = DateTime.Now;
            stores.CreatedBy    = "101";
            stores.ModifiedBy   = "101";
            _Context.tbl_Store.Add(stores);
            _Context.Configuration.ValidateOnSaveEnabled = true;
            _Context.SaveChanges();
            status = true;
            return(status);
            // for new users
        }
 public ActionResult EditStores(StoreViewModel svm)
 {
     if (ModelState.IsValid)
     {
         try
         {
             tbl_Store store = _db.tbl_Store.Where(p => p.StoreId == svm.StoreId).FirstOrDefault();
             store.StoreId       = svm.StoreId;
             store.StoreName     = svm.StoreName;
             store.StoreLocation = svm.StoreLocation;
             store.StoreCapacity = svm.StoreCapacity;
             _db.SaveChanges();
             ViewBag.Message = "Store Updated Successfully.";
             return(RedirectToAction("Store"));
         }
         catch (Exception e)
         {
             return(View("Error", new HandleErrorInfo(e, "Admin", "EditStore")));
         }
     }
     return(RedirectToAction("Store"));
 }
 public ActionResult InsertStore(StoreViewModel svm)
 {
     if (ModelState.IsValid)
     {
         try
         {
             tbl_Store store = new tbl_Store();
             store.StoreId       = svm.StoreId;
             store.StoreName     = svm.StoreName;
             store.StoreLocation = svm.StoreLocation;
             store.StoreCapacity = svm.StoreCapacity;
             _db.tbl_Store.Add(store);
             _db.SaveChanges();
             ViewBag.Message = "Store Created Successfully.";
             return(RedirectToAction("Store"));
         }
         catch (Exception e)
         {
             return(View("Error", new HandleErrorInfo(e, "Admin", "InsertStore")));
         }
     }
     return(View());
 }
        public int InsertOrUpdateStore(MinibarModel model)
        {
            try
            {
                using (var db = _connectionData.OpenDbConnection())
                {
                    using (var tran = db.OpenTransaction())
                    {
                        try
                        {
                            if (model.Id > 0)
                            {
                                var query = db.From <tbl_Store>().Where(e => e.Id == model.Id);
                                var up    = db.Select(query).SingleOrDefault();
                                if (up != null)//update store
                                {
                                    up.title  = model.Name;
                                    up.roomid = model.RoomId;
                                    db.Update(up);
                                }
                                var strDel = db.From <tbl_StoreProduct_Config>().Where(e => e.storeid == model.Id);
                                var del    = db.Select(strDel);
                                if (del.Any())
                                {
                                    db.DeleteAll(del);
                                }
                                if (model.Item.Any())//update store product config
                                {
                                    var list = model.Item.Select(item => new tbl_StoreProduct_Config
                                    {
                                        productid   = item.ProductId,
                                        minimize    = item.Limit,
                                        SysHotelID  = comm.GetHotelId(),
                                        datecreated = DateTime.Now,
                                        storeid     = model.Id
                                    });
                                    db.InsertAll(list);
                                }
                                tran.Commit();
                                return(1);
                            }
                            //Insert-------------------------
                            var check  = db.From <tbl_Store>().Where(e => e.roomid == model.RoomId);
                            var isExit = db.Select(check).FirstOrDefault();
                            if (isExit == null) //Nếu roomID tồn tại rồi thì k cho insert nữa
                            {
                                var store = new tbl_Store
                                {
                                    title       = model.Name,
                                    roomid      = model.RoomId,
                                    creatorid   = comm.GetUserId(),
                                    SysHotelID  = comm.GetHotelId(),
                                    datecreated = DateTime.Now,
                                    typeStore   = 2
                                };
                                var idStore = db.Insert(store, true); //insert product
                                if (model.Item.Any())                 //insert store product
                                {
                                    var list = model.Item.Select(item => new tbl_StoreProduct_Config
                                    {
                                        productid   = item.ProductId,
                                        minimize    = item.Limit,
                                        SysHotelID  = comm.GetHotelId(),
                                        datecreated = DateTime.Now,
                                        storeid     = int.Parse(idStore.ToString())
                                    });
                                    db.InsertAll(list);

                                    /*
                                     * var list = model.Item.Select(item => new tbl_StoreProduct
                                     * {
                                     *  productid = item.ProductId,
                                     *  quantity = item.Limit,
                                     *  SysHotelID = comm.GetHotelId(),
                                     *  datecreated = DateTime.Now,
                                     *  storeid = int.Parse(idStore.ToString())
                                     * });
                                     * db.InsertAll(list);
                                     */
                                }
                                tran.Commit();
                                return(1);
                            }
                            return(-100);
                        }
                        catch (Exception)
                        {
                            tran.Rollback();
                            return(-1);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(-1);
            }
        }