Esempio n. 1
0
        public IHttpActionResult GetAllDVBaoCao(DMDonVi CurDonVi)
        {
            //List<DMDonVi> ls = new List<DMDonVi>();
            //if(CurDonVi.LoaiDonVi == "XD")
            //{

            //        var lsDVCS = db.DMDonVis.Where(t => t.IDDVCha == CurDonVi.Id && t.LoaiDonVi == "TT" && t.FInUse == true);
            //        ls.AddRange(lsDVCS);

            //}
            //if (CurDonVi.LoaiDonVi == "TT")
            //{

            //    ls.Add(CurDonVi);

            //}
            //if (CurDonVi.LoaiDonVi == "CUM")
            //{

            //    var lsDVCS = db.DMDonVis.Where(t => t.IDDVQuanLy == CurDonVi.Id && t.LoaiDonVi == "TT" && t.FInUse == true);
            //    ls.AddRange(lsDVCS);

            //}
            var ls = db.DMDonVis.Where(t => t.LoaiDonVi == "TT" && (
                                           (CurDonVi.LoaiDonVi == "XD" && t.IDDVCha == CurDonVi.Id) ||
                                           (CurDonVi.LoaiDonVi == "CUM" && t.IDDVQuanLy == CurDonVi.Id) ||
                                           (CurDonVi.LoaiDonVi == "TT" && t.Id == CurDonVi.Id)
                                           )
                                       );

            return(Ok(ls));
        }
Esempio n. 2
0
        public IHttpActionResult Save([FromBody] DMDonVi ndkt)
        {
            Validate(ndkt);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (ndkt.MaDonVi == null || string.IsNullOrEmpty(ndkt.MaDonVi.Trim()))
            {
                ndkt.MaDonVi = Commons.Common.AutoId(db, "DV");
            }
            if (ndkt.STT == null || ndkt.STT == 0 || string.IsNullOrEmpty(ndkt.STT.ToString().Trim()))
            {
                ndkt.STT = db.DMDonVis.Max(t => t.STT) + 1;
            }

            if (ndkt.Id == null || ndkt.Id == 0)
            {
                db.DMDonVis.Add(ndkt);
                db.SaveChanges();
            }
            else
            {
                db.Entry(ndkt).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(Ok(ndkt));
        }
Esempio n. 3
0
 private void Validate(DMDonVi item)
 {
     if (string.IsNullOrEmpty(item.MaDonVi))
     {
         ModelState.AddModelError("MaDonVi", "Mã đơn vị bắt buộc nhập");
         ModelState.AddModelError("MaDonVi", "has-error");
     }
     if (string.IsNullOrEmpty(item.TenDonVi))
     {
         ModelState.AddModelError("TenDonVi", "Tên đơn vị bắt buộc nhập");
         ModelState.AddModelError("TenDonVi", "has-error");
     }
     if (string.IsNullOrEmpty(item.LoaiDonVi))
     {
         ModelState.AddModelError("LoaiDonVi", "Loại đơn vị bắt buộc chọn");
         ModelState.AddModelError("LoaiDonVi", "has-error");
     }
 }