public async Task <IActionResult> DeleteWS(WorkingscheduleViewModel request) { var result = await _productApiClient.DeleteWorkingSchedule(request.Id); if (result) { TempData["result"] = "Xoá lịch công tác thành công"; _notyf.Success("Xoá lịch công tác thành công"); return(RedirectToAction("IndexWS")); } ModelState.AddModelError("", "Xoá lịch công tác không thành công");//key and message return(View(request)); }
public async Task <IActionResult> CreateWS([FromForm] WorkingscheduleViewModel request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var workingscheduleId = await _ProductService.CreateWS(request); if (workingscheduleId == 0) { return(BadRequest());//400 } var workingschedule = await _ProductService.GetByIdWS(workingscheduleId); return(CreatedAtAction(nameof(GetById), new { id = workingscheduleId }, workingschedule)); }
public async Task <WorkingscheduleViewModel> GetByIdWS(int requestId) { var workingschedule = await _context.WorkingSchedules.FindAsync(requestId); var workingscheduleViewModel = new WorkingscheduleViewModel() { Id = workingschedule.Id, UserName = workingschedule.UserName, EndDate = workingschedule.EndDate, StartDate = workingschedule.StartDate, LyDo = workingschedule.LyDo, Message = workingschedule.Message }; return(workingscheduleViewModel); }
public async Task <int> CreateWS(WorkingscheduleViewModel request) { var workSchedule = new WorkingSchedule() { StartDate = request.StartDate, EndDate = request.EndDate, LyDo = request.LyDo, Message = request.Message, UserName = request.UserName }; _context.WorkingSchedules.Add(workSchedule); await _context.SaveChangesAsync(); return(workSchedule.Id); }
public async Task <IActionResult> EditWS(int id) { var ws = await _productApiClient.GetByIdWS(id); var workingscheduleVm = new WorkingscheduleViewModel() { Id = ws.Id, UserName = ws.UserName, EndDate = ws.EndDate, StartDate = ws.StartDate, LyDo = ws.LyDo, Message = ws.Message }; return(View(workingscheduleVm)); }
public async Task <int> UpdateWS(WorkingscheduleViewModel request) { var workingschedule = await _context.WorkingSchedules.FindAsync(request.Id); if (workingschedule == null) { throw new EShopException($"Không thể tìm thấy một lịch công tác nào có tên là: {request.UserName}"); } workingschedule.UserName = request.UserName; workingschedule.StartDate = request.StartDate; workingschedule.EndDate = request.EndDate; workingschedule.LyDo = request.LyDo; workingschedule.Message = request.Message; return(await _context.SaveChangesAsync()); }
public async Task <IActionResult> EditWS([FromForm] WorkingscheduleViewModel request) { if (!ModelState.IsValid) { return(View(request)); } var result = await _productApiClient.UpdateWorkingSchedule(request); if (result) { //TempData["result"] = "Cập nhập lịch công tác thành công"; _notyf.Success("Cập nhập lịch công tác thành công"); return(RedirectToAction("IndexWS")); } ModelState.AddModelError("", "Cập nhập lịch công tác thất bại"); return(View(request)); }
public async Task <bool> UpdateWorkingSchedule(WorkingscheduleViewModel workingUpdate) { var sessions = _httpContextAccessor.HttpContext.Session.GetString(SystemConstants.AppSettings.Token); var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration[SystemConstants.AppSettings.BaseAddress]); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions); //lấy token var requestContent = new MultipartFormDataContent(); requestContent.Add(new StringContent(workingUpdate.EndDate.ToString()), "EndDate"); requestContent.Add(new StringContent(workingUpdate.StartDate.ToString()), "StartDate"); requestContent.Add(new StringContent(string.IsNullOrEmpty(workingUpdate.UserName) ? "" : workingUpdate.UserName.ToString()), "UserName"); requestContent.Add(new StringContent(string.IsNullOrEmpty(workingUpdate.LyDo) ? "" : workingUpdate.LyDo.ToString()), "LyDo"); requestContent.Add(new StringContent(string.IsNullOrEmpty(workingUpdate.Message) ? "" : workingUpdate.Message.ToString()), "Message"); var response = await client.PutAsync($"/api/products/UpdateWs/" + workingUpdate.Id, requestContent); return(response.IsSuccessStatusCode); }
public async Task <IActionResult> UpdateWS([FromRoute] int workingscheduleId, [FromForm] WorkingscheduleViewModel request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } request.Id = workingscheduleId; var affectedResult = await _ProductService.UpdateWS(request); if (affectedResult == 0) { return(BadRequest()); } return(Ok()); }