Beispiel #1
0
        public void Update(Guid id)
        {
            EmployeePoco employee = context.EmployeePocos.Find(id);

            context.EmployeePocos.Remove(employee);
            context.SaveChanges();
        }
Beispiel #2
0
        public bool SaveEmployee(EmployeeEditViewModel employeeEdit)
        {
            if (employeeEdit != null)
            {
                // using (var context = new AppDbContext())
                //{
                var employee = new EmployeePoco()
                {
                    Id         = employeeEdit.Id,
                    Name       = employeeEdit.Name,
                    ProvinceId = employeeEdit.SelectedProvinceId,
                    Telephone  = employeeEdit.Telephone,
                    PostalCode = employeeEdit.PostalCode,
                    Salary     = employeeEdit.Salary
                };
                employee.ProvincePoco = context.ProvincePocos.Find(employeeEdit.SelectedProvinceId);

                context.EmployeePocos.Add(employee);
                context.SaveChanges();
                return(true);
                // }
            }
            // Return false if customeredit == null or CustomerID is not a guid
            return(false);
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("EmployeeNo,EmployeeName,Salary,DepartmentNo,LastModifyDate")] EmployeePoco employee)
        {
            //var employeeToEdit = mapper.Map<EmployeePoco>(employee);

            if (id != employee.EmployeeNo)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await service.Update(employee);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.EmployeeNo))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentNo"] = new SelectList(await departmentService.GetDepartments(), "DepartmentNo", "DepartmentLocation", employee.DepartmentNo);
            return(View(employee));
        }
Beispiel #4
0
        public void RecordEquality()
        {
            var e1 = new Employee {
                FirstName = "Jim", LastName = "Wooley"
            };
            var e2 = new Employee {
                FirstName = "Jim", LastName = "Wooley"
            };

            Console.WriteLine($"Classes equal: {e1 == e2}");

            var r1 = new EmployeePoco("Jim", "Wooley", "SA");
            // e1.Title = "Sr Delivery Principal";
            var r2 = r1 with {
                Title = "Sr Delivery Principal"
            };
            var r3 = new EmployeePoco("Jim", "Wooley", "SA");

            Console.WriteLine($"r1 equals r2: {r1 == r2}");
            Console.WriteLine($"r1 equals r3: {r1.Equals(r3)}");
            Console.WriteLine($"r1 == r3: {r1 == r3}");

            var(first, last, title) = r1;
            Console.WriteLine(first);
            Console.WriteLine(last);

            var r4 = r1 with {
                Title = "Sr Delivery Principal"
            };
        }
    }
Beispiel #5
0
        void ConditionalExpressionConversions()
        {
            var e1        = new Principal("First", "Middle", "Principal", 3);
            var e2        = new SrPrincipal("First", "Middle", "Sr Principal", 10);
            var multipler = 15;

            EmployeePoco emp = multipler >= 10 ? e2 : e1;
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("EmployeeNo,EmployeeName,Salary,DepartmentNo")] EmployeePoco employee)
        {
            if (ModelState.IsValid)
            {
                await service.Add(employee);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentNo"] = new SelectList(await departmentService.GetDepartments(), "DepartmentNo", "DepartmentLocation", employee.DepartmentNo);
            return(View(employee));
        }
Beispiel #7
0
        public void FromPoco_Success()
        {
            var remute   = new Remute();
            var expected = new EmployeePoco()
            {
                Id = Guid.NewGuid(), FirstName = "Joe", LastName = "Doe"
            };
            var actual = remute.With <Employee>(expected);

            Assert.IsInstanceOfType(actual, typeof(Employee));
            Assert.AreNotSame(expected, actual);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.FirstName, actual.FirstName);
            Assert.AreEqual(expected.LastName, actual.LastName);
        }
Beispiel #8
0
        public void CreateAndRemute_Success()
        {
            var employeePoco = new EmployeePoco()
            {
                Id = Guid.NewGuid(), FirstName = "Joe", LastName = "Doe"
            };
            var id = Guid.NewGuid();

            var actual = employeePoco
                         .Remute <Employee>()
                         .Remute(x => x.Id, id)
                         .Remute(x => x.FirstName, "Foo")
                         .Remute(x => x.LastName, "Bar");

            Assert.IsInstanceOfType(actual, typeof(Employee));
            Assert.AreEqual(id, actual.Id);
            Assert.AreEqual("Foo", actual.FirstName);
            Assert.AreEqual("Bar", actual.LastName);
        }
Beispiel #9
0
        public EmployeeDisplayViewModel GetEmployee(Guid Id)
        {
            //using (var context = new AppDbContext())
            //{
            EmployeePoco employee = context.EmployeePocos
                                    .Where(x => x.Id == Id)
                                    .Include(x => x.ProvincePoco)
                                    .FirstOrDefault();

            var emp = new EmployeeDisplayViewModel()
            {
                Id         = employee.Id,
                Name       = employee.Name,
                Province   = employee.ProvincePoco.Name,
                Telephone  = employee.Telephone,
                PostalCode = employee.PostalCode,
                Salary     = employee.Salary
            };

            return(emp);
            //}
        }