Пример #1
0
        public int  DalSaveNewFurniture(object furniture)
        {
            int           res           = 0;
            Furniture_Dal furniture_dal = new Furniture_Dal();

            furniture_dal = furniture as Furniture_Dal;
            using (KarmenDbContext db = new KarmenDbContext())
            {
                var temp = db.Furniture.Any(c => c.Type == furniture_dal.Type && c.CrossReference == furniture_dal.CrossReference);
                if (temp == false)
                {
                    // Add new element to Db
                    db.Furniture.Add(new Furnitures
                    {
                        IdColour       = furniture_dal.IdColour,
                        Type           = furniture_dal.Type,
                        UseUnuse       = furniture_dal.UseUnuse,
                        CrossReference = furniture_dal.CrossReference
                    });
                    db.SaveChanges();
                    // Get element from Db
                    var users = db.Furniture.Any(c => c.Type == furniture_dal.Type && c.CrossReference == furniture_dal.CrossReference);
                    res = (users == false) ? 0 : 1; //0 - Saving Error; 1 - Saving is correct
                }
                else
                {
                    res = 2; //This note is already created in Db
                }
            }
            return(res);
        }
Пример #2
0
        public int DalChangeExistedFurniture(object furniture)
        {
            int           res           = 0;
            Furniture_Dal furniture_dal = new Furniture_Dal();

            furniture_dal = furniture as Furniture_Dal;
            using (KarmenDbContext db = new KarmenDbContext())
            {
                var temp = db.Furniture.FirstOrDefault(c => c.Id == furniture_dal.Id);

                // Change data
                temp.IdColour       = furniture_dal.IdColour;
                temp.Type           = furniture_dal.Type;
                temp.UseUnuse       = furniture_dal.UseUnuse;
                temp.CrossReference = furniture_dal.CrossReference;
                //Save changes
                db.SaveChanges();
            }
            res = 1;
            return(res);
        }