Example #1
0
        public int DalSaveNewTopMaterial(object topMaterial)
        {
            int             res             = 0;
            TopMaterial_Dal topMaterial_Dal = new TopMaterial_Dal();

            topMaterial_Dal = topMaterial as TopMaterial_Dal;
            using (KarmenDbContext db = new KarmenDbContext())
            {
                var temp = db.TopMaterial.Any(c => c.Type == topMaterial_Dal.Type && c.CrossReference == topMaterial_Dal.CrossReference);
                if (temp == false)
                {
                    // Add new element to Db
                    db.TopMaterial.Add(new TopMaterials
                    {
                        IdColour       = topMaterial_Dal.IdColour,
                        Type           = topMaterial_Dal.Type,
                        CrossReference = topMaterial_Dal.CrossReference,
                        UseUnuse       = topMaterial_Dal.UseUnuse
                    });
                    db.SaveChanges();
                    // Get element from Db
                    var users = db.TopMaterial.Any(c => c.Type == topMaterial_Dal.Type && c.CrossReference == topMaterial_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);
        }
Example #2
0
        public int DalChangeExistedTopMaterial(object topMaterial)
        {
            int             res             = 0;
            TopMaterial_Dal topMaterial_Dal = new TopMaterial_Dal();

            topMaterial_Dal = topMaterial as TopMaterial_Dal;
            using (KarmenDbContext db = new KarmenDbContext())
            {
                var temp = db.TopMaterial.FirstOrDefault(c => c.Id == topMaterial_Dal.Id);
                //Change data
                temp.IdColour       = topMaterial_Dal.IdColour;
                temp.Type           = topMaterial_Dal.Type;
                temp.CrossReference = topMaterial_Dal.CrossReference;
                temp.UseUnuse       = topMaterial_Dal.UseUnuse;
                //Save changes
                db.SaveChanges();
            }
            res = 1;
            return(res);
        }