Beispiel #1
0
        public int DeleteUnit(int id)
        {
            using (Entities db = new Entities())
            {
                base_units unit = db.base_units.Where(t => t.id == id).SingleOrDefault();

                if (unit != null)
                {
                    db.base_units.Remove(unit);
                }

                return(db.SaveChanges());
            }
        }
Beispiel #2
0
        public int EditUnit(Unit unit)
        {
            using (Entities db = new Entities())
            {
                base_units newUnit = db.base_units.Find(unit.ID);

                if (newUnit != null)
                {
                    newUnit.code        = unit.Code;
                    newUnit.name        = unit.Name;
                    newUnit.unittypeid  = unit.UnitTypeID;
                    newUnit.updatedtime = unit.UpdatedTime;

                    return(db.SaveChanges());
                }
            }

            return(0);
        }
Beispiel #3
0
        public int AddUnit(Unit unit)
        {
            using (Entities db = new Entities())
            {
                base_units newUnit = new base_units()
                {
                    code        = unit.Code,
                    name        = unit.Name,
                    unittypeid  = unit.UnitTypeID,
                    path        = unit.Path,
                    parentid    = unit.ParentID,
                    createdtime = unit.CreatedTime,
                    updatedtime = unit.UpdatedTime
                };

                db.base_units.Add(newUnit);
                db.SaveChanges();

                newUnit.path = string.Format("{0}{1}/", newUnit.path, newUnit.id);

                return(db.SaveChanges());
            }
        }