示例#1
0
        public async Task DeleteLicense(SofaLicense license, long userId)
        {
            if (!(await IsUserWriteAuthorized(license, userId)))
            {
                throw new System.UnauthorizedAccessException("Unable to process request");
            }

            _licenseRepo.Delete(license);
            await _licenseRepo.SaveAsync();
        }
示例#2
0
        public Result <License> CreateLicense(DefaultLicense defaultLicense)
        {
            if (defaultLicense == null)
            {
                return(Result <License> .Error());
            }

            var license = new License()
            {
                DefaultLicenseId = defaultLicense.Id,
                Price            = defaultLicense.Price,
                LicenseCode      = Guid.NewGuid().ToString(),
                Seats            = 1
            };

            var licenseId = licenseRepository.Save(license);

            if (licenseId == 0)
            {
                licenseRepository.Delete(license);
                return(Result <License> .Error());
            }

            var modules = defaultLicense.DefaultModules.Select(defaultModule => new Module()
            {
                DefaultModuleId = defaultModule.Id,
                Price           = defaultModule.Price,
                IsActive        = true,
                LicenseId       = license.Id
            });
            var ids = moduleRepository.Save(modules);

            return(Result <License> .Success(license));
        }
示例#3
0
        public bool Delete(long id, string updatedBy)
        {
            //var obj = _licenseRepository.GetById(id);
            //obj.IsActive = false;
            //return _licenseRepository.Update(obj);

            return(_licenseRepository.Delete(id));
        }
示例#4
0
        public void Update(List <LicenseViewModel> newLicenses)
        {
            var licenses       = _licenseRepository.GetAll();
            var maxLicenseCOde = 0;

            if (licenses.Any())
            {
                maxLicenseCOde = Convert.ToInt32(licenses.Max(x => Convert.ToInt32(x.LicenseC)));
            }
            //xoa
            foreach (var license in licenses)
            {
                if (newLicenses.Any(item => item.LicenseC == license.LicenseC) == false)
                {
                    _licenseRepository.Delete(license);
                }
            }
            //update
            foreach (var item in newLicenses)
            {
                if (string.IsNullOrEmpty(item.LicenseC))
                {
                    var addItem = new License_M()
                    {
                        DisplayLineNo = item.DisplayLineNo,
                        LicenseC      = (++maxLicenseCOde).ToString(),
                        LicenseN      = item.LicenseN
                    };
                    _licenseRepository.Add(addItem);
                }
                else
                {
                    var updateLicense = licenses.Where(x => x.LicenseC == item.LicenseC).FirstOrDefault();
                    if (updateLicense != null)
                    {
                        updateLicense.DisplayLineNo = item.DisplayLineNo;
                        updateLicense.LicenseN      = item.LicenseN;
                        _licenseRepository.Update(updateLicense);
                    }
                }
            }
            SaveLicense();
        }