public async Task <JsonResult> GetAllByCompany()
 {
     try {
         var list = _departmentService.GetAll().Result.ToList();
         list = DepartmentUtility.FilterByCompanyID(CurrentUser.CompanyID, list);
         return(Json(new { success = true, data = DepartmentUtility.MsToVMs(list) }, JsonRequestBehavior.AllowGet));
     } catch { return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); }
 }
 public async Task <JsonResult> Update(DepartmentViewModel vm)
 {
     try {
         var model = DepartmentUtility.VMToM(vm);
         model.UpdatedAt = GetCurrentTime();
         _departmentService.Update(model);
         return(Json(new { success = true, data = DepartmentUtility.MToVM(model) }));
     } catch { return(Json(new { success = false })); }
 }
 public async Task <JsonResult> Update(List <DepartmentViewModel> vms)
 {
     try
     {
         for (int i = 0; i < vms.Count; i++)
         {
             var model = DepartmentUtility.VMToM(vms[i]);
             model.UpdatedAt = GetCurrentTime();
             _departmentService.Update(model);
         }
         return(Json(new { success = true, data = vms }));
     }
     catch { return(Json(new { success = false })); }
 }
 public async Task <JsonResult> Insert(DepartmentViewModel vm)
 {
     try {
         vm.ID      = Guid.NewGuid().ToString();
         vm.Company = new CompanyViewModel()
         {
             ID = CurrentUser.CompanyID
         };
         var model = DepartmentUtility.VMToM(vm);
         model.CreatedAt = GetCurrentTime();
         _departmentService.Insert(model);
         return(Json(new { success = true, data = vm }));
     } catch { return(Json(new { success = false })); }
 }
 public async Task <JsonResult> Inserts(List <DepartmentViewModel> vms)
 {
     try {
         for (int i = 0; i < vms.Count; i++)
         {
             vms[i].ID      = Guid.NewGuid().ToString();
             vms[i].Company = new CompanyViewModel()
             {
                 ID = CurrentUser.CompanyID
             };
             var model = DepartmentUtility.VMToM(vms[i]);
             model.CreatedAt = GetCurrentTime();
             _departmentService.Insert(model);
         }
         return(Json(new { success = true, data = vms }));
     } catch { return(Json(new { success = false })); }
 }