public async Task <IActionResult> Delete([FromBody] MasterEmployee masterEmployee) { var status = ""; using (var httpClient = new HttpClient()) { Uri uri = new Uri(_configuration.GetValue <string>("IDSettings:WebApiBaseUrl") + "MasterEmployees/" + masterEmployee.PkempId); MasterEmployee deletedEmployee = new MasterEmployee(); httpClient.DefaultRequestHeaders.Add("ApiKey", _configuration.GetValue <string>("IDSettings:PublicKey")); using (var response = await httpClient.DeleteAsync(uri)) { if (response.StatusCode == System.Net.HttpStatusCode.NoContent) { string apiResponse = await response.Content.ReadAsStringAsync(); deletedEmployee = JsonConvert.DeserializeObject <MasterEmployee>(apiResponse); status = "success"; } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { status = "error"; } } } return(RedirectToAction(nameof(Index))); }
public async Task<IActionResult> Register(EmployeeForRegisterDTO employeeForRegisterDTO) { // validate the request employeeForRegisterDTO.UserName = employeeForRegisterDTO.UserName.ToLower(); if (await _repo.UserExists(employeeForRegisterDTO.UserName)) return BadRequest("User Name Taken"); var empToCreate = new MasterEmployee { // EmpName = employeeForRegisterDTO.EmpName, // Lname = employeeForRegisterDTO.Lname, // Gender = employeeForRegisterDTO.Gender, // DoJ = employeeForRegisterDTO.DoJ, // Email = employeeForRegisterDTO.Email, // IsAdmin = employeeForRegisterDTO.IsAdmin, // deptID = employeeForRegisterDTO.deptID, UserName = employeeForRegisterDTO.UserName }; var createdEmployee = await _repo.Register(empToCreate, employeeForRegisterDTO.Password); // return CreatedAtRoute(); return StatusCode(201); }
public async Task <MasterEmployee> Register(MasterEmployee masterEmployee, string password) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); masterEmployee.PasswordHash = passwordHash; masterEmployee.PasswordSalt = passwordSalt; await _context.MasterEmployees.AddAsync(masterEmployee); await _context.SaveChangesAsync(); return(masterEmployee); }
public async Task <ActionResult <MasterEmployee> > PostMasterEmployee(MasterEmployee masterEmployee) { try { _context.MasterEmployee.Add(masterEmployee); await _context.SaveChangesAsync(); return(NoContent()); } catch (Exception ex) { return(BadRequest()); } }
public async Task <IActionResult> Save([FromBody] MasterEmployee masterEmployee) { var status = ""; List <MasterEmployee> employee = new List <MasterEmployee>(); using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("ApiKey", _configuration.GetValue <string>("IDSettings:PublicKey")); using (var response = await httpClient.GetAsync(_configuration.GetValue <string>("IDSettings:WebApiBaseUrl") + "MasterEmployees/Phone/" + masterEmployee.EmployeePhonenumber)) { string apiResponse = await response.Content.ReadAsStringAsync(); employee = JsonConvert.DeserializeObject <List <MasterEmployee> >(apiResponse); } } if (employee.Count == 0) { MasterEmployee createdEmployee = new MasterEmployee(); using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(masterEmployee), Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Add("Staging", _configuration.GetValue <string>("IDSettings:PublicKey")); httpClient.DefaultRequestHeaders.Add("ApiKey", "clientspecifickey"); using (var response = await httpClient.PostAsync((_configuration.GetValue <string>("IDSettings:WebApiBaseUrl") + "MasterEmployees/"), content)) { if (response.StatusCode == System.Net.HttpStatusCode.NoContent) { string apiResponse = await response.Content.ReadAsStringAsync(); createdEmployee = JsonConvert.DeserializeObject <MasterEmployee>(apiResponse); status = "success"; } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { status = "error"; } } } } else { status = "Exist contact No"; } return(Json(new { status = status })); }
public async Task <IActionResult> Update([FromBody] MasterEmployee masterEmployee) { var status = ""; //List<MasterEmployee> employee = new List<MasterEmployee>(); //using (var httpClient = new HttpClient()) //{ // httpClient.DefaultRequestHeaders.Add("ApiKey", _configuration.GetValue<string>("IDSettings:PublicKey")); // using (var response = await httpClient.GetAsync(_configuration.GetValue<string>("IDSettings:WebApiBaseUrl") + "MasterEmployees/Phone/" + masterEmployee.EmployeePhonenumber)) // { // string apiResponse = await response.Content.ReadAsStringAsync(); // employee = JsonConvert.DeserializeObject<List<MasterEmployee>>(apiResponse); // } //} MasterEmployee updatedEmployee = new MasterEmployee(); using (var httpClient = new HttpClient()) { Uri uri = new Uri(_configuration.GetValue <string>("IDSettings:WebApiBaseUrl") + "MasterEmployees/" + masterEmployee.PkempId); StringContent content = new StringContent(JsonConvert.SerializeObject(masterEmployee), Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Add("AppName", _configuration.GetValue <string>("IDSettings:AppName")); httpClient.DefaultRequestHeaders.Add("AppKey", _configuration.GetValue <string>("IDSettings:AppKey")); httpClient.DefaultRequestHeaders.Add("ClientKey", _configuration.GetValue <string>("IDSettings:ClientKey")); using (var response = await httpClient.PutAsync(uri, content)) { if (response.StatusCode == System.Net.HttpStatusCode.NoContent) { string apiResponse = await response.Content.ReadAsStringAsync(); updatedEmployee = JsonConvert.DeserializeObject <MasterEmployee>(apiResponse); status = "success"; } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { status = "error"; } } } return(Json(new { status })); }
public async Task <IActionResult> Entry(int?id) { if (id == null) { ViewBag.Mode = "C"; ViewBag.PageName = "Employee"; return(View()); } MasterEmployee Employees = new MasterEmployee(); using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("ApiKey", _configuration.GetValue <string>("IDSettings:PublicKey")); using (var response = await httpClient.GetAsync(_configuration.GetValue <string>("IDSettings:WebApiBaseUrl") + "MasterEmployees/" + id)) { string apiResponse = await response.Content.ReadAsStringAsync(); Employees = JsonConvert.DeserializeObject <MasterEmployee>(apiResponse); } } return(View(Employees)); }
public async Task <IActionResult> PutMasterEmployee(int id, MasterEmployee masterEmployee) { if (id != masterEmployee.PkempId) { return(BadRequest()); } List <MasterEmployee> x = new List <MasterEmployee>(); x = await _context.MasterEmployee .Where(uid => uid.EmployeePhonenumber == masterEmployee.EmployeePhonenumber && uid.PkempId != masterEmployee.PkempId) .ToListAsync(); if (x.Count == 0) { _context.Entry(masterEmployee).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); } else { return(BadRequest()); } }