public void AddEmployees() { DateTime thisDay = DateTime.Today; string joinYear = thisDay.Year.ToString(); string joinMonth = thisDay.Month.ToString(); string joinDay = thisDay.Day.ToString(); string birthYear = dateBirth.Value.Year.ToString(); string birthMonth = dateBirth.Value.Month.ToString(); string birthDay = dateBirth.Value.Day.ToString(); employee.EmployeeName = txtName.Text; employee.Address = txtAddress.Text; employee.Phone = txtPhone.Text; employee.Gender = comboGender.Text; employee.Education = txtEducation.Text; employee.Post = comboPost.Text; employee.Salary = Convert.ToInt32(txtSalary.Text); employee.BloodGroup = comboBloodGroup.Text; employee.Joindate = joinDay + "-" + joinMonth + "-" + joinYear; employee.Birthdate = birthDay + "-" + birthMonth + "-" + birthYear; employee.Password = txtPassword.Text; EmployeeServices employeeService = new EmployeeServices(); if (employeeService.Add(employee) == 1) { MessageBox.Show("Record Added Successfully!"); this.Close(); } else { MessageBox.Show("Could not store data!!"); } }
public void ShouldReturnSuccessForAdd() { EmployeeModel employee = new EmployeeModel(); employee.Fullname = "Unit 2"; employee.PhoneNumber = "+9677777777"; employee.Address = "Al-Asbahi St."; employee.DOB = DateTime.Now; employee.Country = "Yemen"; employee.Email = "Abdulrahman" + testNum.ToString() + "@gmail.com"; employee.Gender = "male"; employee.Position = "Worker"; employee.Status = "divorced"; FileInfo fileinfo = new FileInfo("C:\\Users\\alwani\\Downloads\\Wallpaper\\18397.jpg"); byte[] imageByte = new byte[fileinfo.Length]; using (FileStream fs = fileinfo.OpenRead()) { fs.Read(imageByte, 0, imageByte.Length); } employee.PersonalPhoto = imageByte; bool opeartionSucceeded = false; string dataAccessJsonStr = string.Empty; string formattedJsonStr = string.Empty; try { employeeServices.Add(employee); opeartionSucceeded = true; } catch (DataAccessException e) { e.DataAccessStatusInfo.OperationSucceeded = opeartionSucceeded; dataAccessJsonStr = JsonConvert.SerializeObject(e.DataAccessStatusInfo); formattedJsonStr = JToken.FromObject(dataAccessJsonStr).ToString(); } try { Assert.True(opeartionSucceeded); testOutputHelper.WriteLine("The record has been succesfully added"); } finally { testOutputHelper.WriteLine(formattedJsonStr); } }
private void btnAdd_Clicked(object sender, EventArgs e) { Models.Employees emp = new Models.Employees { Name = txtName.Text, Phone = txtPhone.Text, Email = txtEmail.Text, Address = txtAddress.Text }; context.Add(emp); DisplayAlert("added", "added employee successful", "ok"); Navigation.PopAsync(); }
public HttpResponseMessage Post([FromBody] APIModel.Employee employee) { if (!HelperFunctions.fBrowserIsMobile()) { if (employee == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Wrong type is given for either of the field.")); } try { return(Request.CreateResponse(HttpStatusCode.OK, emp_service.Add(employee))); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "You only have read operation.Unauthorized access.")); } }
/// <summary> /// Lưu dữ liệu xuống database, với tham số đầu vào là Model tương ứng /// </summary> /// <param name="model"></param> /// <returns></returns> public EmployeeModel Put(EmployeeModel model) { //Chuyển model thành Model tương dứng dưới database var modelEmp = new Sys_UserInfoEntity() { UserLogin = model.LoginName, Code = model.Code, IsCheckLDAP = true, LDAPDatasource = "1" }; var service = new EmployeeServices(); if (model.ID != Guid.Empty) { modelEmp.ID = model.ID; service.EditEmployees(modelEmp); } else { service.Add <Sys_UserInfoEntity>(modelEmp); } return(model); }