public ActionResult Create(LeaveTypeVM model) { try { // TODO: Add insert logic here if (!ModelState.IsValid) { return(View(model)); } var leaveType = _mapper.Map <LeaveType>(model); leaveType.DateCreated = DateTime.Now; var isSuccess = _repo.Create(leaveType); if (!isSuccess) { ModelState.AddModelError("", "Something went wrong"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> Create(LeaveTypeVM leaveTypeVM) { try { if (!ModelState.IsValid) { return(View(leaveTypeVM)); } var leaveType = mapper.Map <LeaveType>(leaveTypeVM); leaveType.DateCreated = DateTime.Now; var creationResultIsSuccess = await unitOfWork.LeaveTypes.Create(leaveType); if (!creationResultIsSuccess) { ModelState.AddModelError(string.Empty, "Something went wrong..."); } await unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError(string.Empty, "Something went wrong..."); return(View(leaveTypeVM)); } }
public async Task <IActionResult> Delete(int id, LeaveTypeVM leaveTypeVM) { try { if (id == default || !await unitOfWork.LeaveTypes.CheckIfExists(x => x.Id == id)) { return(NotFound()); } var leaveType = await unitOfWork.LeaveTypes.Find(x => x.Id == id); var isDeletionSuccess = unitOfWork.LeaveTypes.Delete(leaveType); if (!isDeletionSuccess) { return(RedirectToAction(nameof(Delete), new { id = id })); } await unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Delete), new { id = id })); } }
public async Task <ActionResult> Delete(int id, LeaveTypeVM model) { try { return(NotFound()); } catch { return(View()); } }
public ActionResult Delete(int id, LeaveTypeVM model) { try { return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
// GET: LeaveTypesController/Edit/5 public ActionResult Edit(int id) { if (!repo.Exists(id)) { return(NotFound()); } LeaveType leaveType = repo.FindById(id); LeaveTypeVM model = mapper.Map <LeaveTypeVM>(leaveType); return(View(model)); }
public ActionResult Delete(int id, LeaveTypeVM model) { // added model to seperate this method from get method we aint gonna use it its gonna be empty try { return(View(model)); } catch { return(View()); } }
public bool Insert(LeaveTypeVM leaveTypeVM) { if (string.IsNullOrWhiteSpace(leaveTypeVM.Name) || string.IsNullOrWhiteSpace(leaveTypeVM.Duration.ToString()) || string.IsNullOrWhiteSpace(leaveTypeVM.Note)) { return(false); } else { return(iLeaveTypeRepository.Insert(leaveTypeVM)); } }
public bool Update(int id, LeaveTypeVM leaveTypeVM) { if (string.IsNullOrWhiteSpace(leaveTypeVM.Name) || string.IsNullOrWhiteSpace(leaveTypeVM.Duration.ToString()) || string.IsNullOrWhiteSpace(leaveTypeVM.Note)) { return(false); } else { return(iLeaveTypeRepository.Update(id, leaveTypeVM)); } }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } LeaveTypeVM = await _context.LeaveTypeVM.FirstOrDefaultAsync(m => m.Id == id); if (LeaveTypeVM == null) { return(NotFound()); } return(Page()); }
public bool Insert(LeaveTypeVM leaveTypeVM) { var push = new LeaveType(leaveTypeVM); myContext.LeaveTypes.Add(push); var result = myContext.SaveChanges(); if (result > 0) { return(true); } else { return(false); } }
public bool Update(int id, LeaveTypeVM leaveTypeVM) { var get = Get(id); if (get != null) { get.Update(leaveTypeVM); myContext.Entry(get).State = EntityState.Modified; var result = myContext.SaveChanges(); return(result > 0); } else { return(false); } }
// POST: api/LeaveTypes public HttpResponseMessage InsertLeaveType(LeaveTypeVM leaveTypesVM) { try { var message = Request.CreateErrorResponse(HttpStatusCode.NotFound, "404 : Data Not Found"); var result = iLeaveTypesService.Insert(leaveTypesVM); if (result) { message = Request.CreateResponse(HttpStatusCode.OK, leaveTypesVM); } return(message); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "500 : Internal Server Error")); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } LeaveTypeVM = await _context.LeaveTypeVM.FindAsync(id); if (LeaveTypeVM != null) { _context.LeaveTypeVM.Remove(LeaveTypeVM); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public ActionResult Delete(LeaveTypeVM model) { try { if (ModelState.IsValid == false) { return(View(model)); } else { } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Delete(int id, LeaveTypeVM model) { try { var isSuccess = _leaveTypeRepo.Delete(_leaveTypeRepo.FindById(id)); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public void InsertOrUpdate(LeaveTypeVM leaveTypeVM) { var client = new HttpClient(); client.BaseAddress = new Uri(get.link); var myContent = JsonConvert.SerializeObject(leaveTypeVM); var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); if (leaveTypeVM.Id.Equals(0)) { var result = client.PostAsync("LeaveTypes", byteContent).Result; } else { var result = client.PutAsync("LeaveTypes/" + leaveTypeVM.Id, byteContent).Result; } }
public ActionResult Delete(LeaveTypeVM model) { try { var leavetype = _mapper.Map <LeaveType>(model); leavetype.DateCreated = DateTime.Now; var isSuccess = _repo.Delete(leavetype); if (!isSuccess) { ModelState.AddModelError("", "somethig went wrong..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public bool Insert(LeaveTypeVM leaveTypeVM) { var pust = new LeaveType(leaveTypeVM); var getStatusTypeParam = myContext.statusTypeParams.Find(leaveTypeVM.StatusTypeParam_Id); pust.StatusTypeParam = getStatusTypeParam; myContext.leaveTypes.Add(pust); var result = myContext.SaveChanges(); if (result > 0) { status = true; } else { return(false); } return(status); }
public async Task <ActionResult> Delete(int id, LeaveTypeVM model) { try { var leavetype = await _unitOfWork.LeaveTypes.Find(q => q.Id == id); if (leavetype == null) { return(NotFound()); } _unitOfWork.LeaveTypes.Delete(leavetype); await _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public async Task <ActionResult> Delete(int id, LeaveTypeVM model) { try { var leaveType = await _repo.FindById(id); var isSuccess = await _repo.Delete(leaveType); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Delete(int id, LeaveTypeVM model) { try { var leaveType = _repository.FindById(id); var isSuccess = _repository.Delete(leaveType); if (!isSuccess) { ModelState.AddModelError("", "The Leave Type was not deleted..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Delete(int id, LeaveTypeVM model) { try { var leaveType = _repo.FindById(id); if (leaveType == null) { return(NotFound()); } var isSuccess = _repo.Delete(leaveType); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public async Task <ActionResult> Edit(LeaveTypeVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var leaveType = _mapper.Map <LeaveType>(model); _unitOfWork.LeaveTypes.Update(leaveType); await _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Something Went Wrong..."); return(View()); } }
public ActionResult Delete(int id, LeaveTypeVM model) { try { var leaveType = _repo.FindById(id); if (!_repo.IsExists(id)) { return(NotFound()); } var result = _repo.Delete(leaveType); if (!result) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public ActionResult Delete(int id, LeaveTypeVM model) { try { var leavetype = _repo.FindByID(id); if (leavetype == null) { return(NotFound()); } var isSuccess = _repo.Delete(leavetype); if (!isSuccess) { ModelState.AddModelError("", "Something went wrong..."); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public bool Update(int id, LeaveTypeVM leaveTypeVM) { var get = Get(id); get.Update(id, leaveTypeVM); var getStatusTypeParam = myContext.statusTypeParams.Find(leaveTypeVM.StatusTypeParam_Id); get.StatusTypeParam = getStatusTypeParam; myContext.Entry(get).State = System.Data.Entity.EntityState.Modified; var result = myContext.SaveChanges(); if (result > 0) { status = true; } else { return(false); } return(status); }
public ActionResult Edit(LeaveTypeVM model) { try { if (ModelState.IsValid == false) { return(View(model)); } var leaveType = _mapper.Map <LeaveType>(model); if (_repo.Update(leaveType) == false) { ModelState.AddModelError("", "Something went wrong"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Delete(int id, LeaveTypeVM model) { try { // TODO: Add delete logic here var leavetype = _repo.FindById(id); if (leavetype == null) { return(NotFound()); } var isSuccess = _repo.Delete(leavetype); if (!isSuccess) { return(BadRequest()); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public JsonResult GetById(int id) { LeaveTypeVM leaveTypeVM = null; var client = new HttpClient(); client.BaseAddress = new Uri(get.link); var responseTask = client.GetAsync("LeaveTypes/" + id); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <LeaveTypeVM>(); readTask.Wait(); leaveTypeVM = readTask.Result; } else { } return(Json(leaveTypeVM, JsonRequestBehavior.AllowGet)); }