Exemplo n.º 1
0
        public bool DeleteProducts([FromBody] SchoolProductsViewModel model)
        {
            SchoolProducts db = _context.SchoolProducts.Where(p => p.ProductId == model.ProductId).FirstOrDefault();

            try
            {
                if (db.ProductId == model.ProductId)
                {
                    Mapper.Map(model, db);
                    _context.SchoolProducts.Remove(db);
                    var result = _context.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                var error = ex.InnerException;
                return(false);
            }
        }
Exemplo n.º 2
0
        public bool AddProducts([FromBody] SchoolProductsViewModel model)
        {
            model.Active = true;

            SchoolProducts db = new SchoolProducts();

            try
            {
                Mapper.Map(model, db);
                db.Type009 = "009";
                _context.SchoolProducts.Add(db);
                var result = _context.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                var error = ex.InnerException;
                return(false);
            }
        }