public Result <License> EditModules(int userId, IEnumerable <ModuleShortInfo> moduleStatusList, bool setEnable) { var user = userRepository.GetById(userId); if (user == null) { return(Result <License> .Error()); } var companyId = user.CompanyId; var company = companyRepository.GetById(companyId); if (company == null) { return(Result <License> .Error()); } var licenseId = company.LicenseId; var switchedModulesIds = moduleStatusList.Where(m => m.Checked).Select(m => m.DefaultModuleId).ToList(); var allModules = moduleRepository.GetByLicenseId(licenseId); if (allModules == null || allModules.Count == 0) { return(Result <License> .Error()); } var switchedModules = allModules.Where(m => switchedModulesIds.Contains(m.DefaultModuleId)).ToList(); if (switchedModules != null && switchedModules.Count != 0) { foreach (var module in switchedModules) { if (module != null && module.LicenseId == licenseId) { if (module.IsActive != setEnable) { if (!module.IsLocked) { module.IsActive = setEnable; moduleRepository.Save(module); } } } } } return(Result <License> .Success(licenseRepository.GetById(licenseId))); }
public ResponseModel <LicenseModel> GetById(int id) { var resp = new ResponseModel <LicenseModel>(); try { var app = AppRepo.GetById(id); if (app != null) { resp.Data = app; resp.Status = 200; resp.Description = "OK"; } else { throw new Exception("Not found"); } } catch (Exception ex) { resp.Status = 500; resp.Description = $"Error: {ex.Message}"; resp.Data = null; } return(resp); }
public async Task <ActionResult> licenceInfo() { var user = userRepository.GetById(User.Identity.GetUserId <int>()); if (user == null) { return(RedirectToAction("Index", "Home")); } var companyId = user.CompanyId; var company = companyRepository.GetById(companyId); var licenseId = company.LicenseId; var license = licenseRepository.GetById(licenseId); var disabledModules = moduleRepository.GetByLicenseId(licenseId, false); var defaultModules = disabledModules.Select(module => defaultModuleRepository.GetById(module.Id)).ToList(); var model = new EditLicenseModules() { LicenseName = defaultLicenseRepository.GetById(license.DefaultLicenseId).Name, LicenseCode = license.LicenseCode, Modules = defaultModules }; return(View(model)); }
public InvoiceForDownload CreateInvoiceForDownload(int id) { var invoice = invoiceRepository.GetById(id); var company = companyRepository.GetById(invoice.Company.Id); var owner = userRepository.GetOwnerByCompanyId(company.Id); var license = licenseRepository.GetById(company.LicenseId); var modules = moduleRepository.GetByLicenseId(license.Id).Where(m => m.IsActive).ToList(); var invoiceForDownload = new InvoiceForDownload { Id = invoice.Id, LicenceCode = license.LicenseCode, CompanyName = company.FullName, ContactPerson = owner.LastName + " " + owner.FirstName, TotalPrice = (modules.Where(m => !m.IsLocked).Sum(m => m.Price) * companyRepository.GetUsersCount(company.Id)), SeatsNumber = license.Seats, Modules = moduleRepository.GetForDownload(modules.Select(m => m.Id).ToArray(), false) }; return(invoiceForDownload); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl = "") { if (!ModelState.IsValid) { return(View(model)); } var user = userRepository.GetByUserName(model.UserName); if (user != null) { var isPasswordCorrect = await userManager.CheckPasswordAsync(user, model.Password); if (isPasswordCorrect) { if (user != null) { var company = companyRepository.GetById(user.CompanyId); if (company != null) { var license = licenseRepository.GetById(company.LicenseId); if (license != null && license.IsLocked) { ModelState.AddModelError("", "Account is locked, please pay the invoice"); return(View(model)); } } await signInManager.SignInAsync(user, isPersistent : false, rememberBrowser : model.RememberMe); return(RedirectToAction("Index", "Home")); } } } ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); }
public UserInfoViewModel GetUserInfo(int id) { var customer = userRepository.GetById(id); var company = GetById(customer.CompanyId); var license = licenseRepository.GetById(company.LicenseId); UserInfoViewModel customerInfo = new UserInfoViewModel() { Id = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, Company = company, License = license, Modules = moduleRepository.GetByLicenseId(license.Id).Select(m => new Models.ViewModels.License.ModuleInfo() { Id = m.Id, Name = defaultModuleRepository.GetById(m.DefaultModuleId).Name, Price = m.Price, isLocked = m.IsLocked }).ToList() }; return(customerInfo); }
public License GetById(long id) { return(_licenseRepository.GetById(id)); }