public ActionResult Delete(int orgId, int accountId) { var acct = DataSession.Single <Account>(accountId); if (acct != null) { // disable ClientAccounts var clientAccounts = DataSession.Query <ClientAccount>().Where(x => x.Account == acct && x.Active).ToList(); foreach (var ca in clientAccounts) { // disable access to this account Provider.Data.ActiveLog.Disable(ca); // check that all clients still have another account var co = ca.ClientOrg; var c = co.Client; throw new Exception("need to do this"); // check if client has any active accounts //bool hasActiveAcct = false; //hasActiveAcct = DataUtility.HasActiveAccount(clientDataRow, dsAccount.Tables["ClientOrg"], dsAccount.Tables["ClientAccount"]); //if (!hasActiveAcct && c != null) //clientDataRow["EnableAccess"] = false; } Provider.Data.ActiveLog.Disable(acct); } return(RedirectToAction("Index", new { orgId })); }
public override void Load() { Message = string.Empty; if (OrgID == 0) { Active = true; return; } Org org = DataSession.Single <Org>(OrgID); if (org == null) { Message = GetAlert("Cannot find OrgID {0}", OrgID); } else { OrgTypeID = org.OrgType.OrgTypeID; OrgName = org.OrgName; NNINOrg = org.NNINOrg; PrimaryOrg = org.PrimaryOrg; Active = org.Active; } }
public ClientModel Post([FromUri] string option, [FromBody] ClientModel model, int id) { ClientModel result = null; switch (option) { case "current": ClientOrg co = DataSession.Single <ClientOrg>(id); ClientOrg mo = DataSession.Single <ClientOrg>(model.ClientOrgID); if (co != null && mo != null) { var cm = DataSession.Query <ClientManager>().FirstOrDefault(x => x.ClientOrg == co && x.ManagerOrg == mo); if (cm == null) { //no existing ClientManager record so create a new one cm = new ClientManager() { ClientOrg = co, ManagerOrg = mo }; DataSession.Insert(cm); } Provider.Data.ActiveLog.Enable(cm); result = ApiUtility.CreateClientModel(cm.ManagerOrg.CreateModel <IClient>()); } break; } return(result); }
public bool Delete(int orgId, int addressId, string addressType) { var entity = DataSession.Single <Address>(addressId); if (entity != null) { DataSession.Delete(new[] { entity }); OrgAddressType type = (OrgAddressType)Enum.Parse(typeof(OrgAddressType), addressType); Org org = DataSession.Single <Org>(orgId); switch (type) { case OrgAddressType.Billing: org.DefBillAddressID = 0; break; case OrgAddressType.Client: org.DefClientAddressID = 0; break; case OrgAddressType.Shipping: org.DefShipAddressID = 0; break; } DataSession.SaveOrUpdate(org); return(true); } else { return(false); } }
public Account Single(int clientId, int?accountId) { if (!accountId.HasValue) { return(null); } var acct = Require <Data.Account>(x => x.AccountID, accountId.Value); var poa = DataSession.Single <Ordering.PurchaseOrderAccount>(new Ordering.PurchaseOrderAccount() { ClientID = clientId, AccountID = accountId.Value }); int cid = 0; bool active = false; if (poa != null) { cid = poa.ClientID; active = poa.Active; } return(new Account() { ClientID = cid, AccountID = acct.AccountID, AccountName = acct.Name, ShortCode = acct.ShortCode, Active = active }); }
public void TestPurchaserMethods() { var query = ClientRepository.GetPurchasers(); Assert.IsTrue(query.Count() > 0); var purch = ClientRepository.AddOrUpdatePurchaser(1301, true); Assert.AreEqual("Getty, James", purch.DisplayName); Assert.IsTrue(ClientRepository.IsPurchaser(purch.ClientID)); var p = ClientRepository.GetPurchaser(1301); Assert.AreEqual("Getty, James", p.DisplayName); ClientRepository.DeletePurchaser(p.PurchaserID); Assert.IsFalse(ClientRepository.IsPurchaser(p.ClientID)); //clean up var entity = DataSession.Single <Ordering.Purchaser>(p.PurchaserID); DataSession.Delete(entity); }
public void LoadRoom() { Message = string.Empty; if (RoomID == 0) { return; } Room room = DataSession.Single <Room>(RoomID); if (room == null) { Message = string.Format("<div class=\"alert alert-danger\" role=\"alert\">Cannot find RoomID {0}</div>", RoomID); } else { ParentID = room.ParentID ?? 0; RoomName = room.RoomName; DisplayName = room.DisplayName; PassbackRoom = room.PassbackRoom; Billable = room.Billable; ApportionDailyFee = room.ApportionDailyFee; ApportionEntryFee = room.ApportionEntryFee; Active = room.Active; } }
public string EnableClientAccount() { ClientAccount ca = GetClientAccount(); if (ca == null) { //No record exists yet so this must be the first association of this client and account. ca = new ClientAccount { ClientOrg = DataSession.Single <ClientOrg>((int)UserClientOrgID), Account = DataSession.Single <Account>((int)AccountID), Manager = false, IsDefault = false }; // Need to save to get the ClientAccountID. DataSession.Insert(ca); } Provider.Data.ActiveLog.Enable(ca); IClient c = DataSession.Single <ClientInfo>(ca.ClientOrg.Client.ClientID); Provider.Data.Client.UpdatePhysicalAccess(c, out string alert); //A final check... if (ca.ClientOrg.ClientOrgID != UserClientOrgID) { throw new Exception(string.Format("EnableClientAccount failed. Expected ClientOrgID: {0}, Actual ClientOrgID: {1}", UserClientOrgID, ca.ClientOrg.ClientOrgID)); } return(alert); }
public bool IsClaimed(int poid, out int purchaserId, out string purchaserName, out string reqNum, out string realPO, out string purchNotes) { var po = DataSession.Single <Ordering.PurchaseOrder>(poid); var result = false; purchaserId = 0; purchaserName = string.Empty; reqNum = string.Empty; realPO = string.Empty; purchNotes = string.Empty; if (po == null) { return(false); } if (po.PurchaserID.HasValue) { purchaserId = po.PurchaserID.Value; var purchaser = DataSession.Single <Data.Client>(purchaserId); purchaserName = purchaser.DisplayName; realPO = po.RealPO; result = true; } reqNum = po.ReqNum; purchNotes = po.PurchaserNotes; return(result); }
public DepartmentModel[] Delete(int id) { var entity = DataSession.Single <Department>(id); var orgId = entity.Org.OrgID; DataSession.Delete(new Department[] { entity }); return(Get(orgId)); }
public AddressModel Post([FromBody] AddressModel model, int orgId) { Address entity; if (model.AddressID > 0) { //update existing entity = DataSession.Single <Address>(model.AddressID); entity.InternalAddress = model.Attention; entity.StrAddress1 = model.StreetAddress1; entity.StrAddress2 = model.StreetAddress2; entity.City = model.City; entity.State = model.State; entity.Zip = model.Zip; entity.Country = model.Country; } else { //add new entity = new Address() { InternalAddress = model.Attention, StrAddress1 = model.StreetAddress1, StrAddress2 = model.StreetAddress2, City = model.City, State = model.State, Zip = model.Zip, Country = model.Country }; } DataSession.SaveOrUpdate(entity); OrgAddressType type = (OrgAddressType)Enum.Parse(typeof(OrgAddressType), model.AddressType); Org org = DataSession.Single <Org>(orgId); switch (type) { case OrgAddressType.Client: org.DefClientAddressID = entity.AddressID; break; case OrgAddressType.Billing: org.DefBillAddressID = entity.AddressID; break; case OrgAddressType.Shipping: org.DefShipAddressID = entity.AddressID; break; } DataSession.SaveOrUpdate(org); return(GetModel(type, entity)); }
public string GetOrgName() { if (ClientOrgID == 0) { return(string.Empty); } else { return(DataSession.Single <Org>(OrgID).OrgName); } }
public AddressModel[] GetAddresses() { //always return 3 items, one for each OrgAddressType List <AddressModel> list = new List <AddressModel>(); Org org = DataSession.Single <Org>(OrgID); list.AddRange(GetAddressModels(OrgAddressType.Client, DataSession.Query <Address>().Where(x => x.AddressID == org.DefClientAddressID).ToArray())); list.AddRange(GetAddressModels(OrgAddressType.Billing, DataSession.Query <Address>().Where(x => x.AddressID == org.DefBillAddressID).ToArray())); list.AddRange(GetAddressModels(OrgAddressType.Shipping, DataSession.Query <Address>().Where(x => x.AddressID == org.DefShipAddressID).ToArray())); return(list.OrderBy(x => x.AddressType).ThenBy(x => x.StreetAddress1).ToArray()); }
public ActionResult Ajax(int id) { var gs = DataSession.Single <LNF.Impl.Repository.Data.GlobalSettings>(id); if (gs != null) { DataSession.Delete(gs); } var items = DataSession.Query <LNF.Impl.Repository.Data.GlobalSettings>(); return(Json(items, JsonRequestBehavior.AllowGet)); }
public override void Load() { Message = string.Empty; if (ClientID == 0) { Active = true; return; } Org org = DataSession.Single <Org>(OrgID); if (org == null) { Message = GetAlert("Cannot find OrgID {0}", OrgID); } else { Client c = DataSession.Single <Client>(ClientID); if (c == null) { Active = true; return; } else { UserName = c.UserName; LName = c.LName; FName = c.FName; MName = c.MName; PrivFlag = Convert.ToInt32(c.Privs); Communities = c.Communities; TechnicalFieldID = c.TechnicalInterestID; Active = c.Active; ClientOrg co = DataSession.Query <ClientOrg>().FirstOrDefault(x => x.Client.ClientID == ClientID && x.Org.OrgID == OrgID); if (co != null) { ClientOrgID = co.ClientOrgID; DepartmentID = co.Department.DepartmentID; RoleID = co.Role.RoleID; Phone = co.Phone; Email = co.Email; IsManager = co.IsManager; IsFinManager = co.IsFinManager; SubsidyStartDate = co.SubsidyStartDate; NewFacultyStartDate = co.NewFacultyStartDate; } } } }
public bool IsInternalOrg() { var org = DataSession.Single <Org>(OrgID); if (org == null) { return(false); } //ChargeTypeID = 5 - 'U of Michigan (US)' is currently the only one //The rest are External Academic [ChargeTypeID = 15] and External Non-Academic [ChargeTypeID = 25] return(org.OrgType.ChargeType.ChargeTypeID == 5); }
public bool Delete([FromUri] string option, [FromBody] ClientModel model, int id = 0) { bool result = false; switch (option) { case "current": ClientOrg co = DataSession.Single <ClientOrg>(id); ClientOrg mo = DataSession.Single <ClientOrg>(model.ClientOrgID); var cm = DataSession.Query <ClientManager>().FirstOrDefault(x => x.ClientOrg == co && x.ManagerOrg == mo && x.Active); if (cm != null) { Provider.Data.ActiveLog.Disable(cm); //remove account access if no other manager manages the acct ClientModel m = ApiUtility.CreateClientModel(co.CreateModel <IClient>()); AccountModel[] currentAccounts = ApiUtility.GetCurrentAccounts(m); ClientModel[] currentManagers = ApiUtility.GetCurrentManagers(m); foreach (AccountModel acct in currentAccounts) { bool hasManagerForAccount = false; foreach (ClientModel mgr in ApiUtility.GetCurrentManagers(acct)) { if (currentManagers.Select(x => x.ClientOrgID).Contains(mgr.ClientOrgID)) { hasManagerForAccount = true; break; } } if (!hasManagerForAccount) { //the client is assigned to an acct but does not have a manager who manages the acct ClientAccount ca = DataSession.Query <ClientAccount>().FirstOrDefault(x => x.ClientOrg.ClientOrgID == m.ClientOrgID && x.Account.AccountID == acct.AccountID); if (!ca.Manager) //do not deactivate if this client is also the acct manager! { Provider.Data.ActiveLog.Disable(ca); } } } result = true; } break; } return(result); }
public Item Add(string partNum, string description, double unitPrice, int vendorId, int?inventoryItemId) { var item = new Ordering.PurchaseOrderItem() { Active = true, Description = description, InventoryItemID = inventoryItemId, PartNum = partNum, UnitPrice = unitPrice, Vendor = DataSession.Single <Ordering.Vendor>(vendorId) }; DataSession.Insert(item); return(CreateItem(item)); }
public void Claim(int poid, int clientId) { var po = DataSession.Single <Ordering.PurchaseOrder>(poid); var ps = DataSession.Query <Ordering.PurchaserSearch>().FirstOrDefault(x => x.POID == poid); var purchaser = DataSession.Single <Data.Client>(clientId); if (po != null && ps != null && purchaser != null) { po.PurchaserID = purchaser.ClientID; // the view must also be updated or PurchaserSearch results won't change ps.PurchaserID = purchaser.ClientID; Tracking.Track(TrackingCheckpoints.Claimed, po.CreateModel <IPurchaseOrder>(), clientId); } }
public Approver AddOrUpdateApprover(int clientId, int approverId, bool isPrimary) { var appr = new Ordering.Approver { ClientID = clientId, ApproverID = approverId, IsPrimary = false }; var existing = DataSession.Single <Ordering.Approver>(appr); if (existing == null) { return(AddApprover(appr, isPrimary)); } else { return(UpdateApprover(existing, isPrimary)); } }
public ActiveLogModel Post([FromBody] ActiveLogModel model) { ActiveLog alog = DataSession.Single <ActiveLog>(model.LogID); if (alog == null) { return(null); } alog.EnableDate = model.EnableDate; DataSession.SaveOrUpdate(alog); return(new ActiveLogModel() { LogID = alog.LogID, EnableDate = alog.EnableDate }); }
public bool Delete([FromBody] AddressModel model, int id) { Address addr = DataSession.Single <Address>(model.AddressID); ClientOrg co = DataSession.Single <ClientOrg>(id); if (addr != null && co != null) { DataSession.Delete(addr); co.ClientAddressID = 0; DataSession.SaveOrUpdate(co); return(true); } return(false); }
public AddressModel Post([FromBody] AddressModel model, int id = 0) { Address addr = DataSession.Single <Address>(model.AddressID); AddressModel result = null; if (addr != null) { addr.City = model.City; addr.Country = model.Country; addr.InternalAddress = model.Attention; addr.State = model.State; addr.StrAddress1 = model.StreetAddress1; addr.StrAddress2 = model.StreetAddress2; addr.Zip = model.Zip; DataSession.SaveOrUpdate(addr); result = ApiUtility.CreateAddressModel("client", addr); } else { //add a new address to this ClientOrg ClientOrg co = DataSession.Single <ClientOrg>(id); if (co != null) { addr = new Address() { City = model.City, Country = model.Country, InternalAddress = model.Attention, State = model.State, StrAddress1 = model.StreetAddress1, StrAddress2 = model.StreetAddress2, Zip = model.Zip }; DataSession.SaveOrUpdate(addr); co.ClientAddressID = addr.AddressID; DataSession.SaveOrUpdate(co); result = ApiUtility.CreateAddressModel("client", addr); } } return(result); }
public string DisableClientAccount() { ClientAccount ca = GetClientAccount(); if (ca == null) { throw new Exception($"Could not find ClientAccount record for ClientOrgID: {UserClientOrgID}"); } Provider.Data.ActiveLog.Disable(ca); IClient c = DataSession.Single <ClientInfo>(ca.ClientOrg.Client.ClientID); Provider.Data.Client.UpdatePhysicalAccess(c, out string alert); return(alert); }
protected void Extend_Command(object sender, CommandEventArgs e) { var clientId = Convert.ToInt32(e.CommandArgument); var authLevel = (ClientAuthLevel)Enum.Parse(typeof(ClientAuthLevel), e.CommandName); var cc = CurrentClients.FirstOrDefault(x => x.ClientID == clientId); if (cc != null) { var rc = DataSession.Single <ResourceClient>(cc.ResourceClientID); rc.Expiration = DateTime.Now.AddMonths(GetCurrentResource().AuthDuration); DataSession.SaveOrUpdate(rc); ClearResourceClientsCache(); } Fill(authLevel); FillClients(); }
public bool SaveRoom() { if (string.IsNullOrEmpty(RoomName)) { Message = string.Format("<div class=\"alert alert-danger\" role=\"alert\">Room name must not be blank</div>", RoomID); return(false); } Room room; if (RoomID == 0) { room = new Room(); } else { room = DataSession.Single <Room>(RoomID); if (room == null) { Message = string.Format("<div class=\"alert alert-danger\" role=\"alert\">Cannot find RoomID {0}</div>", RoomID); return(false); } } int?parentId = null; if (ParentID > 0) { parentId = ParentID; } room.ParentID = parentId; room.RoomName = RoomName; room.DisplayName = string.IsNullOrEmpty(DisplayName) ? null : DisplayName; room.PassbackRoom = PassbackRoom; room.Billable = Billable; room.ApportionDailyFee = ApportionDailyFee; room.ApportionEntryFee = ApportionEntryFee; room.Active = Active; DataSession.SaveOrUpdate(room); return(true); }
public bool GetSingle <T>(string prefix, IList <T> query) where T : class, IDataItem { prefix += ":"; if (Search.StartsWith(prefix)) { if (int.TryParse(Search.Substring(prefix.Length), out int id)) { T item = DataSession.Single <T>(id); if (item != null) { query.Add(item); } } return(true); } return(false); }
protected void Delete_Command(object sender, CommandEventArgs e) { var clientId = Convert.ToInt32(e.CommandArgument); var authLevel = (ClientAuthLevel)Enum.Parse(typeof(ClientAuthLevel), e.CommandName); var cc = CurrentClients.FirstOrDefault(x => x.ClientID == clientId); if (cc != null) { var rc = DataSession.Single <ResourceClient>(cc.ResourceClientID); DataSession.Delete(rc); ClearResourceClientsCache(); CurrentClients.Remove(cc); } Fill(authLevel); FillClients(); }
private string GetOrgName(int orgId) { var org = DataSession.Single <Org>(orgId); if (org == null) { // real mystery here, it just doesn't exist return(string.Format("unknown:{0}", orgId)); } else { if (org.Active) { return(org.OrgName); //this will probably never happen because the DataRow should have been found, this is here only to cover all possibilities } else { return(string.Format("{0} <span style=\"color: #ff0000;\">(INACTIVE)</span>", org.OrgName)); } } }
public DepartmentModel[] Post([FromBody] DepartmentModel model) { if (model.DepartmentID > 0) { //update existing var entity = DataSession.Single <Department>(model.DepartmentID); entity.DepartmentName = model.DepartmentName; DataSession.SaveOrUpdate(entity); return(new DepartmentModel[] { GetModel(entity) }); } else { //add new var entity = new Department() { DepartmentName = model.DepartmentName, Org = DataSession.Single <Org>(model.OrgID) }; DataSession.SaveOrUpdate(entity); return(Get(model.OrgID)); } }