public TMSAttendance AddFromGlobal(TMSAttendanceCreateViewModel Vm)
        {
            var entity = _mapper.Map <TMSAttendanceCreateViewModel, TMSAttendance>(Vm);

            _tmsAttendanceRepository.Add(entity);
            var attendanceGlobal = _attendanceRepository.Get(Vm.AttendanceId);

            if (attendanceGlobal != null)
            {
                attendanceGlobal.Used = 1;
                if (string.IsNullOrEmpty(attendanceGlobal.CompanyUsed))
                {
                    attendanceGlobal.CompanyUsed = "";
                }
                List <string> listCompanyUsed = attendanceGlobal.CompanyUsed.Split(';').ToList();
                if (!listCompanyUsed.Contains(Vm.CompanyId.ToString()))
                {
                    listCompanyUsed.Add(Vm.CompanyId.ToString());
                }
                attendanceGlobal.CompanyUsed = string.Join(";", listCompanyUsed.ToArray());
                _attendanceRepository.Update(attendanceGlobal);
            }
            SaveChanges();
            return(entity);
        }
        public TMSAttendance Add(TMSAttendanceCreateViewModel Vm)
        {
            var entity = _mapper.Map <TMSAttendanceCreateViewModel, TMSAttendance>(Vm);

            _tmsAttendanceRepository.Add(entity);
            SaveChanges();
            return(entity);
        }
 public IActionResult AddFromGlobal([FromBody] TMSAttendanceCreateViewModel Vm)
 {
     if (!ModelState.IsValid)
     {
         var allErrors = ModelState.Values.SelectMany(v => v.Errors);
         return(new BadRequestObjectResult(new GenericResult(false, allErrors)));
     }
     else
     {
         try
         {
             var data = _tmsAttendanceService.AddFromGlobal(Vm);
             return(new OkObjectResult(new GenericResult(true, data)));
         }
         catch (Exception ex)
         {
             return(new OkObjectResult(new GenericResult(false, ex.Message)));
         }
     }
 }