コード例 #1
0
        public IHttpActionResult PutDepartment(int id, Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.Id)
            {
                return(BadRequest());
            }

            db.Entry(department).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: akuplyaev/AjaxMVC
        public PartialViewResult CreateDepartment(Department department)
        {
            db.Departments.Add(department);
            db.SaveChanges();
            var departments = db.Departments;

            return(PartialView("_PartialIndex", departments));
        }
コード例 #3
0
        public IActionResult Post([FromBody] EventType value)
        {
            value.IsActive = true;

            _context.EventTypes.Add(value);
            _context.SaveChanges();

            return(Ok());
        }
コード例 #4
0
        public ActionResult Post([FromBody] Employee value)
        {
            value.IsActive = true;

            _context.Employees.Add(value);
            _context.SaveChanges();

            return(Ok());
        }
コード例 #5
0
        public PartialViewResult DeleteEmployee(int employeeId)
        {
            Employee employee = db.Employees.Find(employeeId);

            db.Employees.Remove(employee);
            db.SaveChanges();
            var list = db.Departments;

            return(PartialView("_PartialIndex", list));
        }
コード例 #6
0
        public IActionResult PostDepartment(string name)
        {
            var department = new Department()
            {
                de_tittle = name
            };

            _context.Add(department);
            _context.SaveChanges();
            return(Ok("Created"));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "PersonId,Name,BeginDate,Grad,sex,Tecnology,Prim")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Persons.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
コード例 #8
0
        public ActionResult Create([Bind(Include = "DepartmentsId,DepartmentName")] Departments departments)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(departments);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(departments));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "JobId,JobName,Salary")] Job job)
        {
            if (ModelState.IsValid)
            {
                db.Jobs.Add(job);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(job));
        }
コード例 #10
0
        public ActionResult Post([FromBody] Deposit value)
        {
            Employee employee = _context.Employees
                                .Where(empl => empl.Id == value.EmployeeId)
                                .FirstOrDefault();

            EmployeeAccount employeeAccount = _context.EmployeesAccounts
                                              .Where(eA => eA.EmployeeId == value.EmployeeId)
                                              .FirstOrDefault();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    //Add Deposits data
                    value.Employee   = employee;
                    value.EmployeeId = employee.Id;
                    value.Date       = DateTime.Now;

                    _context.Deposits.Add(value);
                    _context.SaveChanges();

                    //Add/Update Employee Account data
                    if (employeeAccount == null)
                    {
                        var newEmployeeAccount = new EmployeeAccount()
                        {
                            EmployeeId       = employee.Id,
                            Employee         = employee,
                            Amount           = value.Amount,
                            DateOfLastUpdate = DateTime.Now
                        };

                        _context.EmployeesAccounts.Add(newEmployeeAccount);
                        _context.SaveChanges();
                    }
                    else
                    {
                        employeeAccount.Amount           = employeeAccount.Amount + value.Amount;
                        employeeAccount.DateOfLastUpdate = DateTime.Now;

                        _context.SaveChanges();
                    }

                    dbContextTransaction.Commit();
                }
                catch
                {
                    dbContextTransaction.Rollback();
                }
            }

            return(Ok());
        }
コード例 #11
0
        public ActionResult Create([Bind(Include = "Id,EmployeeName,Designation,DepartmentId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DepartmentName", employee.DepartmentId);
            return(View(employee));
        }
コード例 #12
0
 public ActionResult Create(Department depData)
 {
     try
     {
         // TODO: Add insert logic here
         db.Departments.Add(depData);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         return(View());
     }
 }
コード例 #13
0
 public ActionResult Create(EmployeeModel emp)
 {
     try
     {
         // TODO: Add insert logic here
         DbContext.Employees.Add(emp);
         DbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #14
0
        public void Seed()
        {
            if (_context.Department.Any() || _context.Seller.Any() || _context.SalesRecords.Any())
            {
                return; //se houver algum registro no banco de dados... não faz nada.
            }

            Department d1 = new Department(1, "Eletronics");
            Department d2 = new Department(2, "Books");
            Department d4 = new Department(3, "Tools");
            Department d3 = new Department(4, "Fashions");

            Seller s1 = new Seller(1, "alcides", "*****@*****.**", new DateTime(1979, 07, 19), 2.300, d1);
            Seller s2 = new Seller(2, "daiane", "*****@*****.**", new DateTime(1986, 02, 06), 2.500, d3);
            Seller s3 = new Seller(3, "dalila", "*****@*****.**", new DateTime(1994, 10, 15), 1.300, d4);
            Seller s4 = new Seller(1, "Julnei", "*****@*****.**", new DateTime(2000, 03, 15), 4.300, d3);
            Seller s5 = new Seller(1, "michelle Silva", "*****@*****.**", new DateTime(1990, 11, 09), 2.500, d2);

            SalesRecord sr1 = new SalesRecord(1, new DateTime(2020, 03, 01), 11.000, SaleStatus.Billed, s1);
            SalesRecord sr2 = new SalesRecord(2, new DateTime(2020, 03, 01), 8.000, SaleStatus.Billed, s2);
            SalesRecord sr3 = new SalesRecord(3, new DateTime(2020, 03, 01), 15.000, SaleStatus.Billed, s3);

            _context.Department.AddRange(d1, d2, d3, d4);

            _context.Seller.AddRange(s1, s2, s3, s4, s5);

            _context.SalesRecords.AddRange(sr1, sr2, sr3);

            _context.SaveChanges();
        }
 public string Save(Person somebody)
 {
     //IEnumerable<Person> persons = db.Persons;
     db.Persons.Add(somebody);
     db.SaveChanges();
     return(somebody.Name + " " + somebody.LastName + " added to db sucassefully");
 }
コード例 #16
0
        public ActionResult DeleteEmployee(int?employeeId)
        {
            if (employeeId == null)
            {
                return(HttpNotFound());
            }
            Employee employee = db.Employees.Find(employeeId);

            if (employee == null)
            {
                return(HttpNotFound());
            }
            db.Employees.Remove(employee);
            db.SaveChanges();
            return(RedirectToAction("Index", "Department"));
        }
コード例 #17
0
        public bool  busUpdate(Phongban model)
        {
            try
            {
                using (var _context = new DepartmentContext())
                {
                    var find = _context.Set <Phongban>().FirstOrDefault(x => x.Id == model.Id);
                    if (find != null)
                    {
                        find.Id   = model.Id;
                        find.Name = model.Name;

                        _context.Set <Phongban>().Attach(find);
                        _context.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
コード例 #18
0
 public bool Add(Department entity)
 {
     try
     {
         context.Departments.Add(entity);
         int result = context.SaveChanges();
         if (result > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         throw ex; //throwing wrapper, no stack trace
         //throw;      //rethrow
     }
 }
コード例 #19
0
 public IActionResult Post([FromBody] Department department)
 {
     if (ModelState.IsValid)
     {
         if (db.Departments.Where(e => e.Name == department.Name).Count() == 0)
         {
             department.isEmpty = true;
             db.Departments.Add(department);
             db.SaveChanges();
             return(Ok(department));
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     return(BadRequest(ModelState));
 }
コード例 #20
0
 public IActionResult Post(int depId, [FromBody] Employee employee)
 {
     if (ModelState.IsValid)
     {
         if (db.Employees.Where(e => e.Email == employee.Email).Count() == 0)
         {
             employee.Department = db.Departments.Find(depId);
             db.Employees.Add(employee);
             employee.Department.isEmpty = false;
             db.SaveChanges();
             return(Ok());
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     return(BadRequest(ModelState));
 }
コード例 #21
0
 static void Main(string[] args)
 {
     using (var dept = new DepartmentContext())
     {
         Console.WriteLine("Add Department");
         var deptObj = new Department {
             ID = 1, Name = "IT", Location = "Pune"
         };
         dept.Departments.Add(deptObj);
         dept.SaveChanges();
         Console.WriteLine("Table Created & Record Inserted");
     }
 }
コード例 #22
0
        public string New_Dep(Department newD)
        {
            string res = "the Id is incorrect";
            IEnumerable <Department> departments = db.Departments;

            if (departments.All(dep => dep.Id != newD.Id))
            {
                db.Departments.Add(newD);
                // сохраняем в бд все изменения
                db.SaveChanges();
                res = newD.Name + " added to db sucassefully";
            }
            return(res);
        }
コード例 #23
0
 public ActionResult Create(DepartmentModel dept)
 {
     try
     {
         // TODO: Add insert logic here
         DbContext.Departments.Add(dept);
         DbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #24
0
 static void Main(string[] args)
 {
     using (var dept = new DepartmentContext())
     {
         Console.WriteLine("Add Department");
         var deptObj = new CodeFirst {
             DeptId = 1, Name = "HR", Location = "Pune"
         };
         dept.Departments.Add(deptObj);
         dept.SaveChanges();
         Console.WriteLine("Record entered");
     }
     Console.ReadLine();
 }
コード例 #25
0
 static void Main(string[] args)
 {
     using (var DeptObj = new DepartmentContext())
     {
         Console.WriteLine("Adding Department Details");
         var deptObj = new Department {
             Department_ID = 1, Department_Name = "IT", Department_Location = "Pune"
         };
         DeptObj.Department_Records.Add(deptObj);
         DeptObj.SaveChanges();
         Console.WriteLine("Record Inserted");
     }
     Console.ReadLine();
 }
コード例 #26
0
 public MeetingsController(DepartmentContext context)
 {
     this.db = context;
     if (!db.Meetings.Any())
     {
         db.Meetings.Add(new Meeting {
             Name = "Kostya", EmployeesId = 1
         });
         db.Meetings.Add(new Meeting {
             Name = "Vasya", EmployeesId = 2
         });
         db.SaveChanges();
     }
 }
コード例 #27
0
        static void Main(string[] args)
        {
            using (var dept = new DepartmentContext())
            {
                Console.WriteLine("Add Department");
                var deptobj = new Department {
                    Id = 1, Name = "IT", Location = "Pune"
                };
                dept.Departments.Add(deptobj);
                dept.SaveChanges();
                Console.WriteLine("Record inserted.");
            }

            Console.ReadLine();
        }
コード例 #28
0
        public ActionResult Post([FromBody] DepartmentEvent value)
        {
            EventType eType = _context.EventTypes.Where(eT => eT.Id == value.EventTypeId).FirstOrDefault();

            value.EventType   = eType;
            value.EventTypeId = eType.Id;

            Employee employee = _context.Employees.Where(empl => empl.Id == value.EmployeeId).FirstOrDefault();

            value.Employee   = employee;
            value.EmployeeId = employee.Id;

            _context.DepartmentEvents.Add(value);
            _context.SaveChanges();

            return(Ok());
        }
コード例 #29
0
        public ActionResult CreateDepartment([Bind(Include = "DepartmentId,Name,DateOfAdding")] Department department)
        {
            department.DateInfoChanging = DateTime.Now.ToShortDateString();
            if (ModelState.IsValidField("Name") && ModelState.IsValidField("DateOfAdding"))
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("ShowDepartments"));
            }

            return(View(department));
        }
コード例 #30
0
 public bool busAdd(Phongban phongban)
 {
     try
     {
         using (var _context = new DepartmentContext())
         {
             Phongban pb = new Phongban();
             pb.Name = phongban.Name;
             _context.Add(pb);
             _context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(false);
     }
 }