Example #1
0
        public static bool put_CAT_Nhom(AppEntities db, int ID, DTO_CAT_Nhom item, string Username)
        {
            bool result = false;
            var  dbitem = db.tbl_CAT_Nhom.Find(ID);

            if (dbitem != null)
            {
                dbitem.Code       = item.Code;
                dbitem.Name       = item.Name;
                dbitem.GhiChu     = item.GhiChu;
                dbitem.Sort       = item.Sort;
                dbitem.IsDisabled = item.IsDisabled;
                dbitem.IsDeleted  = item.IsDeleted;

                dbitem.ModifiedBy   = Username;
                dbitem.ModifiedDate = DateTime.Now;

                try
                {
                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, null, "DTO_CAT_Nhom", DateTime.Now, Username);

                    result = true;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("put_CAT_Nhom", e);
                    result = false;
                }
            }
            return(result);
        }
Example #2
0
        public IHttpActionResult Get(int id)
        {
            DTO_CAT_Nhom tbl_CAT_Nhom = BS_CAT_Nhom.get_CAT_Nhom(db, id);

            if (tbl_CAT_Nhom == null)
            {
                return(NotFound());
            }

            return(Ok(tbl_CAT_Nhom));
        }
Example #3
0
        public IHttpActionResult Post(DTO_CAT_Nhom tbl_CAT_Nhom)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DTO_CAT_Nhom result = BS_CAT_Nhom.post_CAT_Nhom(db, tbl_CAT_Nhom, Username);


            if (result != null)
            {
                return(CreatedAtRoute("get_CAT_Nhom", new { id = result.ID }, result));
            }
            return(Conflict());
        }
Example #4
0
        public static DTO_CAT_Nhom post_CAT_Nhom(AppEntities db, DTO_CAT_Nhom item, string Username)
        {
            tbl_CAT_Nhom dbitem = new tbl_CAT_Nhom();

            if (item != null)
            {
                dbitem.Code       = item.Code;
                dbitem.Name       = item.Name;
                dbitem.GhiChu     = item.GhiChu;
                dbitem.Sort       = item.Sort;
                dbitem.IsDisabled = item.IsDisabled;
                dbitem.IsDeleted  = item.IsDeleted;

                dbitem.CreatedBy   = Username;
                dbitem.CreatedDate = DateTime.Now;

                dbitem.ModifiedBy   = Username;
                dbitem.ModifiedDate = DateTime.Now;


                try
                {
                    db.tbl_CAT_Nhom.Add(dbitem);
                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, null, "DTO_CAT_Nhom", DateTime.Now, Username);


                    item.ID = dbitem.ID;

                    item.CreatedBy   = dbitem.CreatedBy;
                    item.CreatedDate = dbitem.CreatedDate;

                    item.ModifiedBy   = dbitem.ModifiedBy;
                    item.ModifiedDate = dbitem.ModifiedDate;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("post_CAT_Nhom", e);
                    item = null;
                }
            }
            return(item);
        }
Example #5
0
        public IHttpActionResult Put(int id, DTO_CAT_Nhom tbl_CAT_Nhom)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tbl_CAT_Nhom.ID)
            {
                return(BadRequest());
            }

            bool result = BS_CAT_Nhom.put_CAT_Nhom(db, id, tbl_CAT_Nhom, Username);

            if (result)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(NotFound());
            }
        }