Beispiel #1
0
        public virtual async Task UpdateTarget(CreateTargetInput input)
        {
            var Target = input.MapTo <Targets>();

            var details = _TenantTargetRepository.GetAll().Where(a => a.TenantId == input.TenantId && a.TargetDate.Month == input.ValidityDate.Month && a.TargetDate.Year == input.ValidityDate.Year).Select(p => p.Value).FirstOrDefault();

            var targetTotal = _TargetRepository.GetAll().Where(a => a.TenantId == input.TenantId && a.Id != input.Id && a.ValidityDate.Month == input.ValidityDate.Month && a.ValidityDate.Year == input.ValidityDate.Year).Select(p => p.TargetAmount).Sum();

            if (details < (targetTotal + input.Total))
            {
                throw new UserFriendlyException("Ooops!", "Target amount is not valid ...");
            }
            else
            {
                int InputYear  = Convert.ToDateTime(input.ValidityDate).Year;
                int InputMonth = Convert.ToDateTime(input.ValidityDate).Month;
                var query      = _TargetRepository.GetAll().Where(p => p.UserId == input.UserId && p.TenantId == input.TenantId && Convert.ToDateTime(p.ValidityDate).Year == InputYear && Convert.ToDateTime(p.ValidityDate).Month == InputMonth && p.Id != input.Id).FirstOrDefault();
                if (query == null)
                {
                    await _TargetRepository.UpdateAsync(Target);
                }
                else
                {
                    throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in Target Type ...");
                }
            }
        }
Beispiel #2
0
 // [AbpAuthorize(AppPermissions.Pages_Administration_Users_TargetCreate, AppPermissions.Pages_Administration_Users_Edit)]
 public async Task CreateOrUpdateTarget(CreateTargetInput input)
 {
     if (input.Id == 0)
     {
         await CreateTarget(input);
     }
     else
     {
         await UpdateTarget(input);
     }
 }