Exemplo n.º 1
0
        public IActionResult Put(int id, [FromBody] EmployeeForInsertingData employeeInfo)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(400));
                }

                var existingEmployee = _employeeRecordService.GetAll().FirstOrDefault(q => q.Id == id);
                if (existingEmployee == null)
                {
                    return(NotFound());
                }

                existingEmployee.FirstName   = employeeInfo.FirstName;
                existingEmployee.LastName    = employeeInfo.LastName;
                existingEmployee.DateCreated = DateTime.Now;
                _employeeRecordService.Update(existingEmployee);
                _employeeRecordService.Save();

                return(Ok());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(StatusCode(500, e.Message));
            }
        }
Exemplo n.º 2
0
        public IActionResult Post([FromBody] EmployeeForInsertingData employeeInfo)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode(400));
                }

                var employee = new Employee()
                {
                    FirstName   = employeeInfo.FirstName,
                    LastName    = employeeInfo.LastName,
                    DateCreated = DateTime.Now
                };
                _employeeRecordService.Add(employee);
                _employeeRecordService.Save();

                return(Ok());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(StatusCode(500, e.Message));
            }
        }