public async Task CreateOrEdit(CreateOrEditUsageMetricRecordDto input)
 {
     if (input.Id == null)
     {
         await Create(input);
     }
     else
     {
         await Update(input);
     }
 }
        protected virtual async Task Update(CreateOrEditUsageMetricRecordDto input)
        {
            var usageMetricRecord = await _usageMetricRecordRepository.FirstOrDefaultAsync((int)input.Id);

            if (input.UnitsConsumed >= usageMetricRecord.UnitsConsumed)
            {
                usageMetricRecord.LastModificationTime = DateTime.Now;
                ObjectMapper.Map(input, usageMetricRecord);
                // UpdateUsageMetric(input.UsageMetricId);
            }
            else
            {
                string roleName     = "Admin";
                bool   okayToUpdate = false;

                if (AbpSession.UserId != null && AbpSession.UserId > 0)
                {
                    if (AbpSession.TenantId != null)
                    {
                        var tenantInfo = await TenantManager.GetTenantInfo();

                        if (tenantInfo?.Tenant.TenantType == "C")
                        {
                            roleName = "Customer Admin";
                        }
                        else if (tenantInfo?.Tenant.TenantType == "V")
                        {
                            roleName = "Vendor Admin";
                        }
                        else if (tenantInfo?.Tenant.TenantType == "A")
                        {
                            roleName = "Asset Owner Admin";
                        }
                    }

                    User userInfo = await UserManager.GetUserByIdAsync((long)AbpSession.UserId);

                    okayToUpdate = await UserManager.IsInRoleAsync(userInfo, roleName); //WHY THE FVCK is this Role check hard-coded here???
                }

                if (okayToUpdate)
                {
                    usageMetricRecord.LastModificationTime = DateTime.Now;
                    ObjectMapper.Map(input, usageMetricRecord);
                    //UpdateUsageMetric(input.UsageMetricId);
                }
                else
                {
                    throw new UserFriendlyException("No permission", "New value must be equal to or higher than previous record");
                }
            }
        }
        protected virtual async Task Create(CreateOrEditUsageMetricRecordDto input)
        {
            var usageMetricRecord = ObjectMapper.Map <UsageMetricRecord>(input);

            if (AbpSession.TenantId != null)
            {
                usageMetricRecord.TenantId = (int?)AbpSession.TenantId;
            }

            await _usageMetricRecordRepository.InsertAsync(usageMetricRecord);

            //UpdateUsageMetric(input.UsageMetricId);
        }