public void ApplyChanges() { var currentDate = DateTime.Now; var moduleNeedToChange = moduleChangeRepository.GetByDate(currentDate.Year, currentDate.Month, null); List <Module> editedModule = new List <Module>(); foreach (var editModule in moduleNeedToChange) { Module module = moduleRepository.GetById(editModule.ModuleId); module.IsLocked = editModule.IsLocked; module.Price = editModule.Price; editedModule.Add(module); } moduleRepository.Save(editedModule); }
public InvoiceForDownload NextInvoice(int companyId) { var currentDate = DateTime.Now; var company = companyRepository.GetById(companyId); var owner = userRepository.GetOwnerByCompanyId(company.Id); var license = licenseRepository.GetById(company.LicenseId); var modules = moduleRepository.GetByLicenseId(license.Id).Where(m => m.IsActive).ToList(); List <ModuleForDownload> modulesForDownload = new List <ModuleForDownload>(modules.Count); foreach (var module in modules) { var changeModule = changeRepository.GetByDate(currentDate.Year, currentDate.Month + 1, module.Id); if (changeModule.Count != 0) { if (!changeModule.First().IsLocked) { var moduleForDownload = moduleRepository.GetForDownload(new[] { changeModule.First().ModuleId }, true).First(); moduleForDownload.Price = changeModule.First().Price; modulesForDownload.Add(moduleForDownload); } } else { if (!module.IsLocked) { modulesForDownload.Add(moduleRepository.GetForDownload(new[] { module.Id }, false).First()); } } } var invoiceForDownload = new InvoiceForDownload { Id = 1, LicenceCode = license.LicenseCode, CompanyName = company.FullName, ContactPerson = owner.LastName + " " + owner.FirstName, TotalPrice = (modulesForDownload.Sum(m => m.Price) * companyRepository.GetUsersCount(companyId)), SeatsNumber = license.Seats, Modules = modulesForDownload }; return(invoiceForDownload); }
public string EditCustomerModules(int licenseId, ModuleInfo[] modules, string startDate = "") { var defaultModules = moduleRepository.GetByLicenseId(licenseId); List <ModuleChange> modulesChange = new List <ModuleChange>(); List <ModuleInfo> modulesInfo = new List <Models.ViewModels.License.ModuleInfo>(); foreach (var defModule in defaultModules) { var res = modules.Where(m => m.Id == defModule.Id && (m.isLocked != defModule.IsLocked || m.Price != defModule.Price)); if (res.Count() > 0) { modulesInfo.Add(res.First()); } } if (modulesInfo.Count > 0) { string[] date = startDate.Split('.'); foreach (ModuleInfo module in modulesInfo) { var changeModule = moduleChangeRepository.GetByDate(int.Parse(date[1]), int.Parse(date[0]), module.Id); if (changeModule.Count != 0) { moduleChangeRepository.Delete(changeModule.First()); } ModuleChange moduleChange = new ModuleChange() { ModuleId = module.Id, IsLocked = module.isLocked, Price = module.Price, StartDate = new DateTime(int.Parse(date[1]), int.Parse(date[0]), 1) }; modulesChange.Add(moduleChange); } moduleChangeRepository.Save(modulesChange); return("All changes was saved"); } return("It is nothing to change"); }