public async Task <ActionResult <Employee> > PostEmployee(Employee employee) { try { if (employee == null) { _logger.LogError("Employee object sent from client is null."); return(BadRequest("Employee object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Employee object sent from client."); return(BadRequest("Invalid model object")); } using (employeeBLL) { await employeeBLL.Create(employee); return(CreatedAtAction("GetEmployee", new { id = employee.Id }, employee)); } } catch (Exception ex) { _logger.LogError($"Something went wrong inside PostEmployee action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public string T01_CreateEmployee() { // Arrange Employee employee = new Employee() { FirstName = "Chris", LastName = "Chen", HiredDate = DateTime.Today }; // Act employee = empBll.Create(employee); empBll.SaveChanges(); // Assert Assert.IsNotNull(employee.Id); return(employee.Id); }
public ActionResult Create(Employee employee, HttpPostedFileBase ImageFile) { if (ImageFile == null) { ModelState.AddModelError("Image", "Please Upload an Image"); } if (ImageFile != null) { bool isValidFormat = common.CheckImageFormat(ImageFile); if (isValidFormat == false) { ModelState.AddModelError("Image", "Only jpg , png , jpeg are allowed"); } else { byte[] convertedImage = common.ConvertImage(ImageFile); employee.Image = convertedImage; } } employee.IsDeleted = false; if (ModelState.IsValid) { status = employeeBll.Create(employee); if (status == true) { ViewBag.Msg = "Employee Successfully Added"; ModelState.Clear(); ViewBag.ReferenceId = dropDown.GetAllEmployee(); ViewBag.OutletId = dropDown.GetAllOutlet(); return(View()); } if (status == false) { ViewBag.Msg = "Employee Added Failed !"; } } ViewBag.ReferenceId = dropDown.GetAllEmployee(); ViewBag.OutletId = dropDown.GetAllOutlet(); return(View(employee)); }
// POST api/<controller> public void Post([FromBody] Employee value) { empBll = new EmployeeBLL(GetXmlPath()); empBll.Create(value); }