public void Delete(int id)
        {
            var employee = Get(id);

            _context.Remove(employee);
            _context.SaveChanges();
        }
        public ActionResult Create([Bind(Include = "Id,Name,PhoneNumber,Address")] Account account)
        {
            if (ModelState.IsValid)
            {
                db.Accounts.Add(account);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(account));
        }
Example #3
0
        public ActionResult Create([Bind(Include = "Id,Name")] Role role)
        {
            if (ModelState.IsValid)
            {
                db.Roles.Add(role);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
        public ActionResult Create([Bind(Include = "Id,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categoryes.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Example #5
0
        public ActionResult Create([Bind(Include = "Id,Name")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Example #6
0
        public ActionResult Create([Bind(Include = "Id,AccountId,Balance")] Bank bank)
        {
            if (ModelState.IsValid)
            {
                db.Banks.Add(bank);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AccountId = new SelectList(db.Accounts, "Id", "Name", bank.AccountId);
            return(View(bank));
        }
        public ActionResult Create([Bind(Include = "Id,UserId,RoleId")] UserRole userRole)
        {
            if (ModelState.IsValid)
            {
                db.UsersRoles.Add(userRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RoleId = new SelectList(db.Roles, "Id", "Name", userRole.RoleId);
            ViewBag.UserId = new SelectList(db.Users, "Id", "Name", userRole.UserId);
            return(View(userRole));
        }
Example #8
0
        public ActionResult Create(Product product, HttpPostedFileBase a)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Category = db.Categoryes.ToList();
            return(View(product));
        }
Example #9
0
 public Task <bool> Delete(T obj)
 {
     try
     {
         _service.Set <T>().Remove(obj);
         _service.SaveChanges();
         return(Task.Run(() => true));
     }
     catch (Exception e)
     {
         return(Task.Run(() => false));
     }
 }
Example #10
0
        public virtual IActionResult CreateVehicle()
        {
            // create a vehicle.
            Vehicle vehicle = new Models.Vehicle();


            Random r    = new Random();
            int    rInt = r.Next(0, 100); //for ints

            vehicle.DisplayName = "Sample Vehicle - " + rInt;
            vehicle.Description = "Sample Description.";
            _context.Vehicles.Add(vehicle);
            _context.SaveChanges();

            var example = _context.Vehicles.ToList();

            return(new ObjectResult(example));
        }
 public void Create(Student student)
 {
     _context.Add(student);
     _context.SaveChanges();
 }
        public static void AddDBDatas(DbTestContext dbTestContext)
        {
            //AddAttributes

            dbTestContext.Attributes.Add(new db.Attribute()
            {
                id = 1, name = "color"
            });
            dbTestContext.Attributes.Add(new db.Attribute()
            {
                id = 2, name = "size"
            });
            dbTestContext.Attributes.Add(new db.Attribute()
            {
                id = 3, name = "material"
            });

            //Add Products
            var ProductId = 0;
            var Name      = "Product ";
            var Price     = 0;
            var sku       = "1000";

            int attributeValueIds = 0;

            for (int i = 0; i < 15; i++)
            {
                ProductId = ProductId + 1;
                Price     = Price + 2;
                sku       = sku + "-" + ProductId;
                dbTestContext.Products.Add(new Product()
                {
                    id = ProductId, name = Name + " - " + ProductId, price = Price, sku = sku
                });



                if (i % 2 == 0)
                {
                    attributeValueIds = attributeValueIds + 1;
                    dbTestContext.AttributeValues.Add(new AttributeValue()
                    {
                        id          = Convert.ToInt32(attributeValueIds),
                        attributeId = 1,
                        productId   = ProductId,
                        value       = "red"
                    });
                    attributeValueIds = attributeValueIds + 1;
                    dbTestContext.AttributeValues.Add(new AttributeValue()
                    {
                        id          = Convert.ToInt32(attributeValueIds),
                        attributeId = 2,
                        productId   = ProductId,
                        value       = "large"
                    });
                }
                else
                {
                    attributeValueIds = attributeValueIds + 1;
                    dbTestContext.AttributeValues.Add(new AttributeValue()
                    {
                        id          = attributeValueIds,
                        attributeId = 1,
                        productId   = ProductId,
                        value       = "green"
                    });
                    attributeValueIds = attributeValueIds + 1;
                    dbTestContext.AttributeValues.Add(new AttributeValue()
                    {
                        id          = attributeValueIds,
                        attributeId = 2,
                        productId   = ProductId,
                        value       = "medium"
                    });
                    attributeValueIds = attributeValueIds + 1;
                    dbTestContext.AttributeValues.Add(new AttributeValue()
                    {
                        id          = attributeValueIds,
                        attributeId = 3,
                        productId   = ProductId,
                        value       = "rock"
                    });
                }
            }



            dbTestContext.SaveChanges();
        }
 public void Create(Item item)
 {
     _context.Add(item);
     _context.SaveChanges();
 }
 public void Add(Checkout checkout)
 {
     _context.Add(checkout);
     _context.SaveChanges();
 }