Ejemplo n.º 1
0
        public int DalSaveNewKindOfBlock(object kindOfBlock)
        {
            int             res             = 0;
            KindOfBlock_Dal kindOfBlock_dal = new KindOfBlock_Dal();

            kindOfBlock_dal = kindOfBlock as KindOfBlock_Dal;
            using (KarmenDbContext db = new KarmenDbContext())
            {
                var temp = db.KindOfBlock.Any(c => c.Name == kindOfBlock_dal.Name && c.CrossReference == kindOfBlock_dal.CrossReference);
                if (temp == false)
                {
                    // Add new element to Db
                    db.KindOfBlock.Add(new KindOfBlocks
                    {
                        Name = kindOfBlock_dal.Name,
                        AdditionalInformation = kindOfBlock_dal.AdditionalInformation,
                        CrossReference        = kindOfBlock_dal.CrossReference
                    });
                    db.SaveChanges();
                    // Get element from Db
                    var users = db.KindOfBlock.Any(c => c.Name == kindOfBlock_dal.Name && c.CrossReference == kindOfBlock_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);
        }
Ejemplo n.º 2
0
        public int DalChangeExistedKindOfBlock(object kindOfBlock)
        {
            int             res             = 0;
            KindOfBlock_Dal kindOfBlock_dal = new KindOfBlock_Dal();

            kindOfBlock_dal = kindOfBlock as KindOfBlock_Dal;
            using (KarmenDbContext db = new KarmenDbContext())
            {
                var temp = db.KindOfBlock.FirstOrDefault(c => c.Id == kindOfBlock_dal.Id);

                // Change data
                temp.Name = kindOfBlock_dal.Name;
                temp.AdditionalInformation = kindOfBlock_dal.AdditionalInformation;
                temp.CrossReference        = kindOfBlock_dal.CrossReference;
                //Save changes
                db.SaveChanges();
            }
            res = 1;
            return(res);
        }