public void RemoveEmployee() { var options = new DbContextOptionsBuilder <CompanyRegisterDbContext>() .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; var employeeService = new EmployeeServices(new CompanyRegisterDbContext(options)); var companyServices = new CompanyServices(new CompanyRegisterDbContext(options)); var company = new Company() { Id = 1, Name = "Apple", PictureUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/160px-Apple_logo_black.svg.png" }; companyServices.AddToDatabase(company); var employee = new Employee() { Id = 1, CompanyId = 1, ExperinceLevel = "A", Name = "Veselin", PictureUrl = "https://images-eu.ssl-images-amazon.com/images/G/31/img16/imports/AGS/MensFashion_Cat_Clothing._V279132526_.jpg", Salary = 1400, VacationDays = 15, StartDate = DateTime.Now }; var secondEmployee = new Employee() { Id = 2, CompanyId = 1, ExperinceLevel = "A", Name = "Pesho", PictureUrl = "https://images-eu.ssl-images-amazon.com/images/G/31/img16/imports/AGS/MensFashion_Cat_Clothing._V279132526_.jpg", Salary = 1400, VacationDays = 15, StartDate = DateTime.Now }; employeeService.AddEmployee(employee); employeeService.AddEmployee(secondEmployee); employeeService.RemoveEmployee(employee); var result = employeeService.GetAllEmployees(); if (result.Count != 1) { Assert.Fail(); } }
public async Task <IActionResult> CreateUserAccount([FromForm] UserAccountCreateViewModel model) { if (ModelState.IsValid) { IdentityUser user = new IdentityUser { UserName = model.Name, Email = model.Email, PhoneNumber = model.PhoneNumber }; var createResult = await UserManager.CreateAsync(user, model.Password); if (createResult.Succeeded) { var createdUser = await UserManager.FindByEmailAsync(model.Email); EmployeeServices.AddEmployee(createdUser.Id, model.Name, model.Email, model.Role); if (await RoleManager.FindByNameAsync(model.Role) == null) { var role = new IdentityRole(model.Role); await RoleManager.CreateAsync(role); await UserManager.AddToRoleAsync(user, role.Name); } else { await UserManager.AddToRoleAsync(user, model.Role); } } } var users = UserManager.Users.ToList(); return(PartialView("_TablePartial", users)); }
public ActionResult Add(AddVM vm) { EmployeeServices empServices = new EmployeeServices(dbContext); DepartmentServices deptService = new DepartmentServices(dbContext); empServices.AddEmployee(new Employee { EmpName = vm.EmpName, EmpJob = vm.EmpJob, EmpSalary = vm.EmpSalary, Department = deptService.SeacrhDepartment(vm.SelectedDept) }); return(RedirectToAction("Index")); }
public IActionResult AddEmployee(Employee employee) { try { _employeeServices.AddEmployee(employee); return(CreatedAtAction("AddEmployee", employee)); } catch (Exception) { return(BadRequest()); } }
static void Main(string[] args) { Employee employee0 = new Employee { FirstName = "Kenan", LastName = "Kurda" }; Employee employee1 = new Employee { FirstName = "Mauro", LastName = "Gay" }; Employee employee2 = new Employee { FirstName = "Timothy", LastName = "Hsu" }; Employee employee3 = new Employee { FirstName = "Toon", LastName = "Penen" }; Employee employee4 = new Employee { FirstName = "Francis", LastName = "Bulu" }; Employee employee5 = new Employee { FirstName = "Emre", LastName = "Elagoz" }; EmployeeServices employeeServices = EmployeeServices.Instance(); employeeServices.AddEmployee(employee0); employeeServices.AddEmployee(employee1); employeeServices.AddEmployee(employee2); employeeServices.AddEmployee(employee3); employeeServices.AddEmployee(employee4); employeeServices.AddEmployee(employee5); Employee e1 = new Employee { FirstName = "Mr", LastName = "Bean" }; EmployeeServices employeeServices177777 = EmployeeServices.Instance(); employeeServices177777.AddEmployee(e1); //var items = employeeServices.GetEmployee("Toon"); //foreach (var item in items) //{ // Console.WriteLine($"First Name {item.FirstName} Last Name: {item.LastName}"); //} var allEmployees = employeeServices.GetAllEmployees(); foreach (var item in allEmployees) { Console.WriteLine($"FirstName: {item.FirstName.PadRight(10)} LastName: {item.LastName.PadRight(25)}"); } }
public IActionResult Create([FromBody] Employee emp) { int logincode = _service.AddEmployee(emp); if (logincode > 0) { Boolean SendCode = SendMail.SendloginCode(logincode.ToString(), emp.EmpEmail, emp.EmpName); return(Ok(emp)); } else { return(BadRequest("there error")); } }
public IActionResult Create([FromForm] GetEmployee emp) { try { string res = ""; if (emp.EmpProfilePicture != null) { // add profile picture res = AddFiles.AddImage(emp.EmpProfilePicture, emp.EmpId); } Hash hash = new Hash(); emp.EmpPassword = hash.HashPassword(emp.EmpPassword); Employee employee = new Employee(); employee.EmpId = emp.EmpId; employee.EmpEmail = emp.EmpEmail; employee.EmpPassword = emp.EmpPassword; employee.EmpName = emp.EmpName; employee.EmpContact = emp.EmpContact; employee.EmpAddress1 = emp.EmpAddress1; employee.EmpAddress2 = emp.EmpAddress2; employee.EmpGender = emp.EmpGender; employee.PositionPId = emp.PositionPId; employee.DepartmentDprtId = emp.DepartmentDprtId; employee.EmpProfilePicture = res; employee.ProjectPrId = emp.ProjectId; int regitercode = _service.AddEmployee(employee); if (regitercode > 0) { // if there register code send it bt email Boolean SendCode = SendMail.SendloginCode(regitercode.ToString(), emp.EmpEmail, emp.EmpName); return(Ok(emp)); } else { return(BadRequest("there error")); } } catch { return(BadRequest()); } }
[HttpPost] //using Model Binding as opposed to FormCollection object public ActionResult Create(Employee newEmp) { try { if (ModelState.IsValid) { ////if collection object is being used //string name = collection["Name"]; //string age = collection["Age"]; //string joiningDate = collection["JoiningDate"]; //Employee newEmp = new Employee { Id = id + 1, Name = name, Age = int.Parse(age), JoiningDate = DateTime.Parse(joiningDate) }; employeeService.AddEmployee(newEmp); return(RedirectToAction("Index")); } return(View(newEmp)); //returns the error message } catch { return(View()); } }
public static void AddEmployee(string email, string prefix, string fname, string mname, string lname, string nickName, string suffix, int agencyId, string phone, string fax, string jobTitle, DateTime membershipStartDate, string emailLocation) { Employee employee = new Employee() { Email = email, Prefix = prefix, FirstName = fname, LastName = lname, MiddleName = mname, NickName = nickName, Suffix = suffix, AgencyId = agencyId, Phone = phone, Fax = fax, JobTitle = jobTitle, MembershipStartDate = membershipStartDate }; EmployeeServices employeeService = new EmployeeServices(); employeeService.AddEmployee(employee); HttpContext.Current.Session["empAdded"] = "1"; }