public ActionResult Index() { var users = UserManager.Users.ToArray(); var context = new ApplicationDbContext(); var db = new AromaContext(); var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context)); var roles = roleManager.Roles.ToArray(); var userRoles = new List<UserRoleViewModel>(); ViewBag.Roles = roles.Select(m=>m.Name).ToArray(); foreach (var user in users) { var userClient = db.UserClients.FirstOrDefault(m => m.UserId.ToString() ==user.Id); var data = new UserRoleViewModel() { Id = user.Id, Username = user.UserName, Roles = user.Roles.Select(m=>roles.First(r=>r.Id== m.RoleId).Name).ToList() }; if (userClient != null) { data.ClientId = userClient.ClientId.ToString(); } userRoles.Add(data); } return View(userRoles.OrderBy(m=>m.Username).ToList()); }
public void Add(PickingListHeader header, AromaContext db) { foreach (var detail in header.PickingListDetail) { var shipment = (from item in this.Shipments where item.groupId.Equals(detail.GroupId) select item).FirstOrDefault(); if (shipment == null) { if (detail.Address == null) detail.Address = detail.Client.DeliveryAddress; var cell = db.GetContact(detail.ClientID, Generic.enumContactType.Cell); //var contact = detail.Client.Contact?.Where(m => m.Active && m.ContactTypeID == 3).FirstOrDefault(); shipment = new Shipment() { ClientDescription = string.Format("{0} {1} ({2})", detail.Client.FullNames, detail.Client.ClientSurname, detail.ClientID), PhoneNumber = cell,// contact==null?string.Empty:contact.ContactName, Address = detail.Address, ClientId = detail.ClientID, groupId = detail.GroupId, ItemCount = 1 }; this.Shipments.Add(shipment); } else { shipment.ItemCount++; } } }
public ActionResult Index() { var adminView = new AdministratorViewModel(); adminView.Menu = new AdministratorMenu(); var context = new AromaContext(); adminView.Menu.Save(context); return View(adminView); }
public static void CreateClientBankingDetails(AromaContext db,int clientId, string initials, string surname, int cellContactId, int homeContactId, int workContactId, int emailContactId) { const string accountHolderText = "Self"; const string accountTypeText = "Cheque"; const string BankText = "ABSA"; var accountHolder = db.AccountHolders.FirstOrDefault(m => m.AccountHolderName == accountHolderText); if (accountHolder == null) { string errorMessage = string.Format("Account holder \"{0}\" not defined in lookup", accountHolderText); throw new Exception(errorMessage); } var accountType = db.AccountTypes.FirstOrDefault(m => m.AccountTypeName == accountTypeText); if (accountType == null) { string errorMessage = string.Format("Account type \"{0}\" not defined in lookup", accountTypeText); throw new Exception(errorMessage); } var bank = db.Banks.FirstOrDefault(m => m.BankName == BankText); if (bank == null) { string errorMessage = string.Format("Bank name \"{0}\" not defined in lookup", BankText); throw new Exception(errorMessage); } var branch = db.Branches.FirstOrDefault(m => m.BankId == bank.BankId); if (branch == null) { string errorMessage = string.Format("No branch defined for \"{0}\" not defined in lookup", BankText); throw new Exception(errorMessage); } if (db.BankingDetails.Where(m => m.ClientID == clientId).Count() == 0) { var bankingDetail = new BankingDetail() { Initials = initials, Surname = surname, AccountHolderID = accountHolder.AccountHolderId, AccountTypeID = accountType.AccountTypeId, BankID = bank.BankId, ClientID = clientId, CommencementDate = DateTime.Now.AddMonths(1), SalaryDate = DateTime.Now, AccountNumber = "0", BranchID = branch.BranchId, CellContact = db.Contacts.First(m => m.ContactId == cellContactId).ContactName, HomeContact = db.Contacts.First(m => m.ContactId == homeContactId).ContactName, WorkContact = db.Contacts.First(m => m.ContactId == workContactId).ContactName, EmailContact = db.Contacts.First(m => m.ContactId == emailContactId).ContactName, Interval=1, Active = false }; db.BankingDetails.Add(bankingDetail); db.SaveChanges(); } }
public AdministratorMenu() { this.Text = "Administrator Menu"; var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext())); var role = RoleManager.FindByName("Administrator"); var roleId = Guid.Parse(role.Id); using (var db = new AromaContext()) { var menuItems = db.SystemMenuList.Where(m => m.Active && m.RoleId.Equals(roleId)).Select(m=>m.SystemMenuListItem).OrderBy(m=>m.Text).ToArray(); foreach (var mnuItem in menuItems) { this.Add(mnuItem.Text, mnuItem.ActionName, mnuItem.ControllerName,mnuItem.Parameters); } } //fixed items for now, could be fetched from DB at a later stage /* this.Add("System Accounts", "Index", "Account"); this.Add("Client Type", "Index", "ClientTypes"); this.Add("Ethnic Group", "Index", "EthnicGroups"); this.Add("Title", "Index", "Titles"); this.Add("Language", "Index", "Languages"); this.Add("Income Group", "Index", "IncomeGroups"); this.Add("Address Type", "Index", "AddressTypes"); this.Add("Province", "Index", "Provinces"); this.Add("Country", "Index", "Countries"); this.Add("Contact Type", "Index", "ContactTypes"); this.Add("Account Holder", "Index", "AccountHolders"); this.Add("Account Type", "Index", "AccountTypes"); this.Add("Bank", "Index", "Banks"); this.Add("Branch", "Index", "Branches"); this.Add("Contact Type", "Index", "ContactTypes"); this.Add("Financial Account","Index","finAccounts"); this.Add("Client Account", "Index", "finClientAccounts"); this.Add("Client Subscription", "Index", "ClientSubscriptions"); this.Add("Client", "Index", "Clients"); this.Add("Product", "Index", "Products"); this.Add("Subscription", "Index", "Subscriptions"); this.Add("Debit Order", "Index", "DebitOrders"); this.Add("Tickets", "Index", "SupportTickets"); this.Add("Ticket Templates", "Index", "SystemTicketTemplates"); this.Add("SMS", "Manage", "SystemSMS"); this.Add("SMS Templates", "Index", "SystemSMSTemplates"); this.Add("Postal Codes", "Index", "PostalCodes");*/ //////////////////////////////////////////////////////// //must always be under admin if (this.Where(m => m.Text == "Menu Control").Count() == 0) { this.Add("Menu Control", "Index", "SystemMenuLists",""); } ///////////////////////////////////////////////////////// }
internal void LoadNetwork(AromaContext db) { this.Parent = db.Clients.Find(this.ClientId).ResellerID; var children = (from item in db.Clients where item.ResellerID == this.ClientId select item.ClientId).ToArray(); this.DirectChildCount = children.Length; this.DescendantCount = this.DirectChildCount; this.Children = new List<NetworkClient>(); foreach (var id in children) { var child = new NetworkClient(); child.LoadNetwork(db, id); this.Children.Add(child); this.DescendantCount += child.DescendantCount; } }
public UserMenu(string srole) { this.Text = "Menu"; var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext())); var role = RoleManager.FindByName(srole); var roleId = Guid.Parse(role.Id); using (var db = new AromaContext()) { var menuItems = db.SystemMenuList.Where(m =>m.Active && m.RoleId.Equals(roleId)).Select(m => m.SystemMenuListItem).OrderBy(m => m.Text).ToArray(); foreach (var mnuItem in menuItems) { this.Add(mnuItem.Text, mnuItem.ActionName, mnuItem.ControllerName, mnuItem.Parameters); } } ////fixed items for now, could be fetched from DB at a later stage //this.Add("Capture Application", "Create", "Clients"); //this.Add("Client", "Index", "Clients"); //this.Add("Support tickets", "Index", "SupportTickets"); }
public JsonResult UpdateUserClient(Guid userId, string clientIdText) { try { int clientId = 0; if (int.TryParse(clientIdText, out clientId)) { var db = new AromaContext(); var client = db.Clients.FirstOrDefault(m=>m.ClientId == clientId); if (client == null) { return Json("Client not found"); } else { var userClient = db.UserClients.FirstOrDefault(m=>m.UserId.Equals(userId)); if (userClient == null) { userClient = new UserClient() {UserId=userId }; db.UserClients.Add(userClient); } userClient.ClientId = clientId; db.SaveChanges(); return Json(string.Empty); } } else { return Json("Invalid client Id"); } } catch (Exception ex) { return Json(ex.Message); } }
public static Invoice GetInvoice(AromaContext db, Guid id) { var invoice = db.Invoices.Find(id); if (invoice == null) { invoice = new Invoice() { InvoiceId = id, Number = string.Format("INB{0:000000}", db.Invoices.Count() + 1) }; db.Invoices.Add(invoice); db.SaveChanges(); } return invoice; }
public static void SendSMSEvent(AromaContext db, int systemSMSEventId, int clientId, Guid userId, Guid? source, params KeyValuePair<string, string>[] pars) { try { var systemSMSevent = db.SystemSMSEvents.Find(systemSMSEventId); var template = systemSMSevent.SystemSMSTemplate; var client = db.Clients.Find(clientId); if (!source.HasValue) source = userId; try { if (systemSMSevent.Active) { var contact = db.Contacts.Where(m => m.ContactTypeID == 3 && m.ClientID == clientId).FirstOrDefault(); var smsSub = new SystemSMSTemplateModel(template.Text, client, db); smsSub.EventInfo = pars; var textResult = smsSub.Generate(); if (contact != null) { var sms = (from item in db.SystemSMSes where item.ClientID == clientId && item.SMSDescription == textResult select item).FirstOrDefault(); if (sms == null) { sms = new SystemSMS() { Active = true, ClientID = clientId, iDate = DateTime.Now, Number = contact.ContactName, SMSDescription = textResult, Source = source, SystemSMSStatusId = 1 }; db.SystemSMSes.Add(sms); db.SaveChanges(); } } else { var ticket = new SupportTicket() { ClientID = clientId, Description = string.Format("An attemt was made to send a SMS to this client ({0}) but the cell number could not be found.\r\n{1}", clientId, textResult), iDate = DateTime.Now, SupportTicketStatusID = 1, SupportTicketTypeId = 2, UserID = userId }; db.SupportTickets.Add(ticket); db.SaveChanges(); } } } catch (Exception ex) { try { var ticket = new SupportTicket() { ClientID = client.ClientId, Description = string.Format("Unable to create system sms:\"{0}\" Message:{1}", template.Description, ex.Message), iDate = DateTime.Now, SupportTicketStatusID = 1, SupportTicketTypeId = 2, UserID = userId }; db.SupportTickets.Add(ticket); db.SaveChanges(); } catch { throw; } } } catch { throw; } }
internal void LoadNetwork(AromaContext db, int clientId) { if (clientId == 0) clientId = db.Clients.Where(m => m.ResellerID == null).First().ClientId; this.ClientId = clientId; LoadNetwork(db); }
internal static void PersistTicket(AromaContext db, Guid systemEventId, Guid id,int clientId, int supportTicketType, string text, Guid userId) { var evnt = db.SystemEvents.Find(systemEventId); var links = (from item in db.SystemLinks where item.Parent.Equals(id) select item.Child).ToArray(); var ticket = (from item in db.SupportTickets where links.Contains(item.SupportTicketId) && item.SupportTicketTypeId == supportTicketType select item).FirstOrDefault(); if (ticket == null) { ticket = new SupportTicket() { ClientID = clientId, Description = text, iDate = DateTime.Now, SupportTicketId=Guid.NewGuid(), SupportTicketStatusID = 1, SupportTicketTypeId = supportTicketType, UserID = evnt.UserId }; db.SupportTickets.Add(ticket); var link = new SystemLink() { Parent =id, Child = ticket.SupportTicketId, Created = DateTime.Now, UserID = userId, LinkId = Guid.NewGuid() }; db.SystemLinks.Add(link); db.SaveChanges(); } }
internal static Guid Create(Guid accountId, int clientId, AromaContext db) { var clientAccount = (from item in db.ClientAccounts where item.AccountId.Equals(accountId) && item.ClientID == clientId select item).FirstOrDefault(); if (clientAccount == null) { var account = (from item in db.Accounts where item.AccountId.Equals(accountId) select item).FirstOrDefault(); if (account == null) { throw new Exception("Cannot create client account"); } if (account.IsSystemAccount) return account.AccountId; clientAccount = new finClientAccount() { AccountId = account.AccountId, Active = true, ClientID = clientId, ClientAccountId = Guid.NewGuid() }; db.ClientAccounts.Add(clientAccount); db.SaveChanges(); } return clientAccount.ClientAccountId; }
private static bool IsOwnOrder(AromaContext db, int? clientId, Guid userId) { if (clientId.HasValue) { var userClient = db.UserClients.FirstOrDefault(m => m.UserId.Equals(userId)); if (userClient != null) { return (userClient.ClientId == clientId.Value); } } return false; }
internal static string GetInvoice(AromaContext db, int orderLineId) { var orderHeaderId = db.OrderLines.Find(orderLineId).OrderHeaderId; return GetInvoice(db, orderHeaderId).Number; }
internal static string Name(AromaContext db, Guid accountId) { var account = db.Accounts.Where(m => m.AccountId.Equals(accountId)).FirstOrDefault(); if (account == null) { var clientAccount = db.ClientAccounts.Where(m => m.ClientAccountId.Equals(accountId)).FirstOrDefault(); if (clientAccount != null) return clientAccount.Account.AccountName; } else { return account.AccountName; } return "Unknown"; }
public static AccountMovementViewModel LoadGlobalJournals(AromaContext db, DateTime fromDate, DateTime toDate) { toDate = toDate.AddDays(1).AddMilliseconds(1); var model = new AccountMovementViewModel(); model.FromDate = fromDate; model.ToDate = toDate; model.Journals = new List<finJournal>(); var finJournals = (from item in db.Journals where item.EffectiveDate >= fromDate && item.EffectiveDate <= toDate orderby item.JournalDate select item).ToList(); while (finJournals.Count > 0) { var leg1 = finJournals[0]; var leg2 = (from finJournal item in finJournals where leg1.CorrespondingJournalId.Equals(item.JournalId) select item).FirstOrDefault(); if (leg2 == null) { leg2 = db.Journals.First(m => m.JournalId.Equals(leg1.CorrespondingJournalId)); } else { finJournals.Remove(leg2); } finJournals.Remove(leg1); model.Journals.Add(leg1); model.Journals.Add(leg2); } model.Accounts = (from item in db.Accounts.Where(m=>m.Active).ToArray() select new AccountViewModel() { AccountDescription = item.AccountName, AccountId = item.AccountId, IsClientAccount = false }).ToList(); int index = 0; foreach (var acc in model.Accounts) { AccountBalance openBal = db.Database.SqlQuery<AccountBalance>(string.Format(Generic.sqlGlobalBalanceAtDate, fromDate.ToString(dtfmt), acc.AccountId)).First(); AccountBalance closingBal = db.Database.SqlQuery<AccountBalance>(string.Format(Generic.sqlGlobalBalanceAtDate, toDate.ToString(dtfmt), acc.AccountId)).First(); /* AccountBalance openBal = db.Database.SqlQuery<AccountBalance>( "spBalanceAtDate", new SqlParameter("date", fromDate), new SqlParameter("accountId", acc.AccountId) ).First(); AccountBalance closingBal = db.Database.SqlQuery<AccountBalance>("spBalanceAtDate", toDate, acc.AccountId).First();*/ acc.OpenBalance = openBal.Balance; acc.Balance = closingBal.Balance; acc.FutureBalance = closingBal.FutureBalance; acc.FutureBalanceDate = closingBal.FutureDate; acc.columnIndex = index; index++; } return model; }
public static AccountMovementViewModel LoadJournals(AromaContext db, DateTime fromDate, DateTime toDate, int? clientId, Guid? clientAccountId) { toDate = toDate.AddDays(1).AddMilliseconds(1); var model = new AccountMovementViewModel(); var clientAccountIds = new Guid[0]; model.FromDate = fromDate; model.ToDate = toDate; model.ClientId = clientId; model.ClientAccountId = clientAccountId; model.Journals = new List<finJournal>(); if (clientAccountId.HasValue) { clientAccountIds = new Guid[] {clientAccountId.Value }; } else { clientAccountIds = (from item in db.ClientAccounts where (clientId.HasValue && item.ClientID == clientId.Value) || !(clientId.HasValue) select item.ClientAccountId).ToArray(); } /* var test1 = (from item in db.Journals where clientAccountIds.Contains(item.AccountID) select item).ToList(); var test2 = (from item in test1 where item.EffectiveDate >= fromDate orderby item.JournalDate select item).ToList(); var test3 = (from item in test1 where item.EffectiveDate <= toDate orderby item.JournalDate select item).ToList(); */ var finJournals = (from item in db.Journals where item.EffectiveDate >= fromDate && item.EffectiveDate <= toDate && clientAccountIds.Contains(item.AccountID) //&& item.Index == 1 orderby item.JournalDate select item).ToList(); while (finJournals.Count > 0) { var leg1 = finJournals[0]; var leg2 = (from finJournal item in finJournals where leg1.CorrespondingJournalId.Equals(item.JournalId) select item).FirstOrDefault(); if (leg2 == null) { leg2 = db.Journals.First(m => m.JournalId.Equals(leg1.CorrespondingJournalId)); } else { finJournals.Remove(leg2); } finJournals.Remove(leg1); model.Journals.Add(leg1); model.Journals.Add(leg2); } var RelevantAccounts = model.Journals.Select(m => m.AccountID).Distinct().ToArray(); model.Accounts = (from item in db.Accounts.ToArray() where RelevantAccounts.Count() == 0|| RelevantAccounts.Contains(item.AccountId) select new AccountViewModel() { AccountDescription = item.AccountName, AccountId = item.AccountId, IsClientAccount = false }).ToList(); model.Accounts.AddRange((from item in db.ClientAccounts.Where(m=>(!clientId.HasValue || (clientId.HasValue && m.ClientID == clientId.Value))).ToArray() where RelevantAccounts.Contains(item.ClientAccountId) select new AccountViewModel() { AccountDescription = db.Accounts.First(m=>m.AccountId.Equals(item.AccountId)).AccountName, AccountId = item.ClientAccountId, IsClientAccount = true }) ); int index = 0; foreach (var acc in model.Accounts) { if (clientAccountId.HasValue && !acc.AccountId.Equals(clientAccountId.Value)) { acc.IsClientAccount = false; } AccountBalance openBal = db.Database.SqlQuery<AccountBalance>(string.Format(Generic.sqlBalanceAtDate, fromDate.ToString(dtfmt), acc.AccountId)).First(); AccountBalance closingBal = db.Database.SqlQuery<AccountBalance>(string.Format(Generic.sqlBalanceAtDate, toDate.ToString(dtfmt), acc.AccountId)).First(); /* AccountBalance openBal = db.Database.SqlQuery<AccountBalance>( "spBalanceAtDate", new SqlParameter("date", fromDate), new SqlParameter("accountId", acc.AccountId) ).First(); AccountBalance closingBal = db.Database.SqlQuery<AccountBalance>("spBalanceAtDate", toDate, acc.AccountId).First();*/ acc.OpenBalance = openBal.Balance; acc.Balance = closingBal.Balance; acc.FutureBalance = closingBal.FutureBalance; acc.FutureBalanceDate = closingBal.FutureDate; acc.columnIndex = index; index++; } return model; }