public EmployeeResponse Put(Employee employee)
 {
     var response = new EmployeeResponse();
     response.Errors = this.Service.Add(employee);
     response.Employee = employee;
     return response;
 }
Exemple #2
0
        public Dictionary<string, string> Update(Employee employee)
        {
            if (employee == null) throw new ArgumentNullException("employee");

            Dictionary<string, string> errors = this.GetValidationErrors(employee);

            if (errors.Count == 0)
                this.Repository.Update(employee);

            return errors;
        }
Exemple #3
0
        public Dictionary<string, string> GetValidationErrors(Employee employee)
        {
            var errors = new Dictionary<string, string>();

            if (string.IsNullOrEmpty(employee.Name))
                errors.Add("Name", "The name is required.");

            if(employee.Name.Length > 50)
                errors.Add("Name", "The name length must be less than 50 caracters.");

            return errors;
        }
        public void Add(Employee employee)
        {
            MemoryDatabase.Add(employee); // somente para demonstração, não usar em produção
            MemoryDatabase[MemoryDatabase.Count - 1].Id = MemoryDatabase.Count; // somente para demonstração, não usar em produção

            // abaixo segue modelo para usar banco de dados, nesse exemplo estou usando tudo na memória.
            /*using(SqlConnection connection = SqlHelper.GetConnection())
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = "INSERT INTO Employees(Name) VALUES(@Name); SELECT @@IDENTITY AS Id;";
                command.Parameters.AddWithValue("@Name", employee.Name);

                IDataReader sqlReader = command.ExecuteReader();

                if (sqlReader.Read())
                {
                    employee.Id = sqlReader.GetInt32(0);
                }
            }*/


        }
 public void Delete(Employee employee)
 {
     this.Service.Delete(employee);
 }
 public void Update(Employee employee)
 {
     throw new NotImplementedException();
 }
 public void Delete(Employee employee)
 {
     this.MemoryDatabase.RemoveAll(x => x.Id == employee.Id);  // somente para demonstração, não usar em produção
 }
Exemple #8
0
        public void Delete(Employee employee)
        {
            if (employee == null) throw new ArgumentNullException("employee");

            this.Repository.Delete(employee);
        }