/// <summary> /// Method that creates employee /// </summary> /// <param name="employee"></param> /// <returns></returns> public Retorno Create(LLEmployee employee) { #region check employe's data if (employee == null) { return(new Retorno { Sucess = false, Message = "Data not informed" }); } try { if (GetEmployee(employee.name, employee.department)) { return new Retorno { Sucess = false, Message = "Employee alread exists in data base" } } ; } catch (Exception ex) { _log.Error("Fail to check employee's data. Cause : {0}", ex.Message); return(new Retorno { Sucess = false, Message = "It's not possible check employee's data. Please try again later." }); } #endregion #region create try { employee.id = _nextId; Employees.Add(employee); _nextId += 1; } catch (Exception ex) { _log.Error("Fail to includade employee's data. Cause : {0}", ex.Message); return(new Retorno { Sucess = false, Message = "It's not possible include employee's data. Please try again later." }); } return(new Retorno { Sucess = true, Employee = employee }); #endregion }
public HttpResponseMessage PostProduto([FromBody] LLEmployee item) { Retorno retornoDB = employeeDB.Create(item); if (retornoDB.Sucess) { var response = Request.CreateResponse <LLEmployee>(HttpStatusCode.Created, retornoDB.Employee); string uri = Url.Link("DefaultApi", new { id = retornoDB.Employee.id }); response.Headers.Location = new Uri(uri); return(response); } return(new HttpResponseMessage(new HttpStatusCode())); }
/// <summary> /// Method check if an employee alread exists /// </summary> /// <param name="name">Employee's name</param> /// <param name="department">Employee's department</param> /// <returns></returns> public bool GetEmployee(string name, string department) { #region check if employee exists LLEmployee emp = Employees.Where(x => x.name.ToLower() == name.ToLower() && x.department.ToLower() == department).FirstOrDefault(); if (emp == null) { return(false); } return(true); #endregion }