コード例 #1
0
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Products.Add(product);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var groupList = _context.Categories.Select(c => new SelectListItem
            {
                Text  = c.Name,
                Value = c.Id.ToString()
            }).ToList();

            groupList.Insert(0, new SelectListItem
            {
                Value    = "0",
                Text     = "Seçin",
                Selected = true,
                Disabled = true
            });

            ViewBag.Categories = groupList;

            return(View(product));
        }
コード例 #2
0
 public ActionResult Edit(Homework homeworkInput, string deleteHomeWorks, List <int> deleteIdsList)
 {
     if (!string.IsNullOrEmpty(deleteHomeWorks))
     {
         Delete(deleteIdsList);
         return(RedirectToAction("Edit"));
     }
     //add the homework u get
     _homeworkDb.DbSet.Add(homeworkInput);
     _homeworkDb.SaveChanges();
     return(RedirectToAction("Edit"));
 }
コード例 #3
0
        public static AccountBook Update(AccountBook account)
        {
            var data = (AccountBook)_HomeworkDbContext.AccountBook.Find(account.Id);

            data.Amounttt   = account.Amounttt;
            data.Categoryyy = account.Categoryyy;
            data.Dateee     = account.Dateee;
            data.Remarkkk   = account.Remarkkk;
            var result = _HomeworkDbContext.SaveChanges();

            return(data);
        }
コード例 #4
0
        public static string Execute(string[] command)
        {
            var id      = int.Parse(command[1]);
            var address = string.Join(" ", command.Skip(2));

            using (var db = new HomeworkDbContext())
            {
                var employee = db.Employees.Find(id);
                employee.Address = address;

                db.SaveChanges();
            }

            return("Address is set");
        }
コード例 #5
0
        public static string Execute(string[] command)
        {
            var id   = int.Parse(command[1]);
            var date = DateTime.ParseExact(command[3], "dd-MM-yyyy", CultureInfo.InvariantCulture);

            using (var db = new HomeworkDbContext())
            {
                var employee = db.Employees.Find(id);

                employee.BirthDay = date;

                db.SaveChanges();
            }

            return($"Birthday is set");
        }
コード例 #6
0
        public static string Execute(string[] command)
        {
            var empId = int.Parse(command[1]);
            var manId = int.Parse(command[2]);

            using (var db = new HomeworkDbContext())
            {
                var employee = db.Employees.Find(empId);
                var manager  = db.Employees.Find(manId);

                manager.Employees.Add(employee);

                db.SaveChanges();
            }

            return($"Manager with Id {manId} is now a Manager to Employee with Id {empId}");
        }
コード例 #7
0
        public static string Execute(string[] command)
        {
            var firstName = command[1];
            var lastName  = command[2];
            var salary    = decimal.Parse(command[3]);

            using (var db = new HomeworkDbContext())
            {
                var employee = new EmployeeDto()
                {
                    FirstName = firstName,
                    LastName  = lastName,
                    Salary    = salary
                };

                db.Employees.Add(Mapper.Map <Employee>(employee));

                db.SaveChanges();
            }

            return($"Employee {firstName} {lastName} with Salary {salary} was added");
        }
コード例 #8
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }