Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            //Xóa header
            NT_NUOC_NGOT _obj = _context.NT_NUOC_NGOT.Find(id);

            _context.NT_NUOC_NGOT.Remove(_obj);
            _context.NT_NUOC_NGOT_DETAIL.Where(o => o.ID_NUOC_NGOT == _obj.ID).ToList().ForEach(o => _context.NT_NUOC_NGOT_DETAIL.Remove(o));
            //Update thay đổi vào DB
            _context.SaveChanges();
            this.Information(string.Format(FDB.Common.Constants.NOTIFY_DELETE_SUCCESS, "Nuôi thủy sản nước ngọt"));
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Create()
        {
            this.LoadDanhMuc();
            NT_NUOC_NGOT model = new NT_NUOC_NGOT();

            model.NGUOI_NHAP = User.Identity.Name;
            model.NGAY_NHAP  = DateTime.Now;
            model.NAM        = DateTime.Now.Year;
            //model.THANG = DateTime.Now.Month;

            return(View(model));
        }
Exemplo n.º 3
0
        //async Task<ActionResult>
        public ActionResult Edit(FormCollection _form, NT_NUOC_NGOT _obj)
        {
            List <string> lstKeyName = _form.AllKeys.ToList().Where(s => s.StartsWith("ddlID_DOITUONG_NUOI_NGOT_")).ToList <String>();
            List <int>    lstInt     = new List <int>();

            lstKeyName.ForEach(o => lstInt.Add(int.Parse(o.Split('_')[o.Split('_').Count() - 1])));

            if (ModelState.IsValid)
            {
                var model = _context.NT_NUOC_NGOT.First(o => o.ID == _obj.ID);
                FDB.Common.Helpers.CopyObject <NT_NUOC_NGOT>(_obj, ref model);
                model.NGUOI_NHAP = User.Identity.Name;
                var dbEntityEntry = _context.Entry(model);

                _context.NT_NUOC_NGOT.Attach(model);
                _context.Entry(model).State = System.Data.Entity.EntityState.Modified;

                //Xóa những detail cũ:
                _context.NT_NUOC_NGOT_DETAIL.Where(o => o.ID_NUOC_NGOT == _obj.ID).ToList().ForEach(o => _context.NT_NUOC_NGOT_DETAIL.Remove(o));

                //Thêm mới detail đã sửa
                int Id = _obj.ID;

                if (lstKeyName != null)
                {
                    for (int i = 0; i < lstInt.Count; i++)
                    {
                        NT_NUOC_NGOT_DETAIL _objDetail = new Models.NT_NUOC_NGOT_DETAIL();
                        FDB.Common.Helpers.GetValueForm <NT_NUOC_NGOT_DETAIL>(_form, lstInt[i], ref _objDetail);
                        _objDetail.ID_NUOC_NGOT = Id;
                        _context.NT_NUOC_NGOT_DETAIL.Add(_objDetail);
                    }
                }
                //Save data:
                _context.SaveChanges();

                this.Information(string.Format(FDB.Common.Constants.NOTIFY_UPDATE_SUCCESS, "Nuôi thủy sản nước ngọt"));
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["_SUCCESS"] = "";
                this.LoadDanhMuc();
                _obj.DSNT_NuocNgotDetail = new List <NT_NUOC_NGOT_DETAIL>();
                //build html :
                int    maxID   = 0;
                String strHTML = string.Empty; //this.GenderHTML(lstInt, _form, ref maxID);
                ViewBag.sEditHTML = strHTML;
                ViewBag.sMaxID    = maxID + 1;
                return(View(_obj));
            }
        }
Exemplo n.º 4
0
        public ActionResult Create(FormCollection _form, NT_NUOC_NGOT _obj)
        {
            List <string> lstKeyName = _form.AllKeys.ToList().Where(s => s.StartsWith("ddlID_DOITUONG_NUOI_NGOT_")).ToList <String>();
            List <int>    lstInt     = new List <int>();

            lstKeyName.ForEach(o => lstInt.Add(int.Parse(o.Split('_')[o.Split('_').Count() - 1])));

            if (ModelState.IsValid)
            {
                //Save Header
                _obj.NGUOI_NHAP = User.Identity.Name;
                _obj.NGAY_NHAP  = DateTime.Now;
                _context.NT_NUOC_NGOT.Add(_obj);
                _context.SaveChanges();

                int Id = _obj.ID;

                if (lstKeyName != null)
                {
                    for (int i = 0; i < lstInt.Count; i++)
                    {
                        NT_NUOC_NGOT_DETAIL _objDetail = new Models.NT_NUOC_NGOT_DETAIL();
                        FDB.Common.Helpers.GetValueForm <NT_NUOC_NGOT_DETAIL>(_form, lstInt[i], ref _objDetail);
                        _objDetail.ID_NUOC_NGOT = Id;
                        _context.NT_NUOC_NGOT_DETAIL.Add(_objDetail);
                    }
                    //Save data:
                    _context.SaveChanges();
                }

                this.Information(string.Format(FDB.Common.Constants.NOTIFY_ADD_SUCCESS, "Nuôi thủy sản nước ngọt"));
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["_SUCCESS"] = "";
                this.LoadDanhMuc();
                //build html :
                int    maxID   = 0;
                String strHTML = string.Empty; //this.GenderHTML(lstInt, _form, ref maxID);
                ViewBag.AddHTML = strHTML;
                ViewBag.sMaxID  = maxID + 1;
                return(View(_obj));
            }
        }