public ActionResult ViewAccounts() { AccountModel viewModel = new AccountModel(); List <AccountDO> accountDOList = dataMethods.ViewAllAccounts(); foreach (AccountDO accountDO in accountDOList) { AccountPO accountPO = new AccountPO(); accountPO = MappingMethods.MapAccountDOtoPO(accountDO); viewModel.accountList.Add(accountPO); } return(View(viewModel)); }
private void LoadData(AccountPO entity) { if (entity != null) { this.FillFrom(entity); Avatars = Utility.DataCache.AccountAvatars.CacheList(entity.Id); Contacts = Utility.DataCache.AccountContacts.CacheList(entity.Id); Logs = Utility.DataCache.AccountLog.CacheList(entity.Id); Messages = Utility.DataCache.AccountMessages.CacheList(entity.Id); Notes = Utility.DataCache.AccountNote.CacheList(entity.Id); Relations = Utility.DataCache.AccountRelation.CacheList(entity.Id); Styles = Utility.DataCache.DataStyle.CacheList(entity.Id); OrganizationRelations = Utility.DataCache.OrganizationMember.CacheList(0, entity.Id); Organizations = Utility.DataCache.Organization.CacheList() .FindAll(o => OrganizationRelations.Any(x => x.OrganizationId == o.Id)); Subscribes = Utility.DataCache.Subscribe.CacheList(entity.Id, 0); Projects = Utility.DataCache.Project.CacheList() .FindAll(o => o.IsPublic || o.CreatorAccountId == entity.Id || Subscribes.Any(x => x.ProjectId == o.Id)); Schedules = new List <SchedulePO>(); foreach (var projectPo in Projects) { Schedules.AddRange(Utility.DataCache.Schedule.CacheList(projectPo.Id)); } } else { Avatars = new List <AccountAvatarsPO>(); Contacts = new List <AccountContactsPO>(); Logs = new List <AccountLogPO>(); Messages = new List <AccountMessagesPO>(); Notes = new List <AccountNotePO>(); Relations = new List <AccountRelationPO>(); Styles = new List <DataStylePO>(); OrganizationRelations = new List <OrganizationMemberPO>(); Organizations = new List <OrganizationPO>(); Projects = new List <ProjectPO>(); Schedules = new List <SchedulePO>(); Subscribes = new List <SubscribePO>(); } }
public static AccountPO SaveAccount( ChannelPO channel, AccountPO account, AccountAvatarsPO avatar, List <AccountContactsPO> contacts, List <AccountMessagesPO> messages, List <SchedulePO> schedules ) { var now = DateTime.Now; var trans = new Transaction(); try { trans.Begin(); #region DBOP var bllAccount = new DB.Agent.MssqlHelper <AccountPO>(); var bllAccountAvatars = new DB.Agent.MssqlHelper <AccountAvatarsPO>(); var bllAccountContacts = new DB.Agent.MssqlHelper <AccountContactsPO>(); var bllAccountMessages = new DB.Agent.MssqlHelper <AccountMessagesPO>(); var bllProject = new DB.Agent.MssqlHelper <ProjectPO>(); var bllSchedule = new DB.Agent.MssqlHelper <SchedulePO>(); #region avatar and account var condition = account == null ? string.Format("ChannelId={0} AND ChannelIdentity='{1}'", avatar.ChannelId, avatar.ChannelIdentity) : string.Format("ChannelId={0} AND ChannelIdentity='{1}' AND AccountId={2}", avatar.ChannelId, avatar.ChannelIdentity, account.Id); var avatarExists = bllAccountAvatars.FindSingle(condition, trans.DbConnection, trans.DbTrans); if (avatarExists == null) { if (account == null) { account = new DB.Entity.Base.AccountPO { NickName = avatar.DisplayName, Valid = true, UpdateTime = now, CreateTime = now, LastSignin = now, MobileVerifyTime = now, EmailVerifyTime = now }; Logger.Debug(account.SerializeXml()); account = bllAccount.Insert(account, trans.DbConnection, trans.DbTrans); } avatarExists = new AccountAvatarsPO { ChannelId = avatar.ChannelId, ChannelIdentity = avatar.ChannelIdentity, DisplayName = avatar.DisplayName, Code = avatar.Code, Token = avatar.Token, TokenGenerated = avatar.TokenGenerated, TokenExpires = avatar.TokenExpires, UpdateTime = avatar.UpdateTime, RefreshToken = avatar.RefreshToken, AccountId = account.Id, Valid = true, CreateTime = now, SynchroTime = now, SynchroDuration = 600 }; avatarExists.UpdateTime = now; Logger.Debug(avatarExists.SerializeXml()); avatar = bllAccountAvatars.Insert(avatarExists, trans.DbConnection, trans.DbTrans); } else { avatar.Id = avatarExists.Id; avatar.AccountId = avatarExists.AccountId; avatar.Valid = avatarExists.Valid; avatar.CreateTime = avatarExists.CreateTime; avatar.UpdateTime = now; avatar.SynchroTime = now; if (avatar.SynchroDuration == 0) { avatar.SynchroDuration = 600; } Logger.Info(avatar.SerializeXml()); bllAccountAvatars.Update(avatarExists, avatar, trans.DbConnection, trans.DbTrans); account = bllAccount.FindById(avatar.AccountId, trans.DbConnection, trans.DbTrans); } Utility.DataCache.AccountAvatars.InitCache(account.Id); #endregion Logger.Debug("REFRESH ACCOUNT CACHE"); var all = Refresh(account); #region contacts if (contacts != null && contacts.Any()) { Logger.Debug("SAVE CONTACTS"); foreach (var a in contacts) { var a0 = all.Contacts.FindLast( o => o.ChannelId == a.ChannelId && o.ChannelIdentity == a.ChannelIdentity && o.AccountId == account.Id); if (a0 == null) { a0 = new AccountContactsPO { AccountId = account.Id, ChannelId = a.ChannelId, ChannelIdentity = a.ChannelIdentity, DisplayName = a.DisplayName, Detail = a.Detail, CreateTime = now, Valid = true, UpdateTime = now }; a0 = bllAccountContacts.Insert(a0, trans.DbConnection, trans.DbTrans); } else { a0.DisplayName = a.DisplayName; a0.Detail = a.Detail; a0.UpdateTime = now; bllAccountContacts.Update(a, a0, trans.DbConnection, trans.DbTrans); } } Utility.DataCache.AccountContacts.InitCache(account.Id); } #endregion #region messages if (messages != null && messages.Any()) { Logger.Debug("SAVE MESSAGES"); foreach (var b in messages) { var b0 = all.Messages.FindLast( o => o.ChannelId == b.ChannelId && o.ChannelIdentity == b.ChannelIdentity && o.ToAccountId == account.Id); if (b0 == null) { b0 = new AccountMessagesPO { ToAccountId = account.Id, ChannelId = b.ChannelId, ChannelIdentity = b.ChannelIdentity, MessageType = b.MessageType, MessageSubject = b.MessageSubject, MessageContent = b.MessageContent, CreateTime = b.CreateTime, Valid = true, Weblink = b.Weblink, UpdateTime = now }; b0 = bllAccountMessages.Insert(b0, trans.DbConnection, trans.DbTrans); } else { b0.MessageType = b.MessageType; b0.MessageSubject = b.MessageSubject; b0.MessageContent = b.MessageContent; b0.Weblink = b.Weblink; b0.UpdateTime = now; b0.CreateTime = b.CreateTime; bllAccountMessages.Update(b, b0, trans.DbConnection, trans.DbTrans); } } Utility.DataCache.AccountMessages.InitCache(account.Id); } #endregion #region p&s if (schedules != null && schedules.Any()) { Logger.Debug("SAVE SCHEDULES"); var projectCode = avatar.Code + "." + account.Id + "." + channel.Id; var projectExists = Utility.DataCache.Project.CacheList().FindLast(o => o.ChannelId == channel.Id && o.CreatorAccountId == account.Id && o.ProjectCode == projectCode); var projectSchedules = new List <SchedulePO>(); if (projectExists == null) { projectExists = new ProjectPO { ProjectCode = projectCode, Valid = true, CreateTime = now, UpdateTime = now, ProjectName = avatar.DisplayName + "@" + channel.ChannelName, ChannelId = channel.Id, CreatorAccountId = account.Id, EnterDeadline = now }; Logger.Debug(projectExists.SerializeXml()); projectExists = bllProject.Insert(projectExists, trans.DbConnection, trans.DbTrans); } else { projectSchedules = Utility.DataCache.Schedule.CacheList(projectExists.Id); } Utility.DataCache.Project.InitCache(); foreach (var c in schedules) { var c0 = projectSchedules.FindLast( o => o.ProjectId == projectExists.Id && o.ScheduleIdentity == c.ScheduleIdentity); if (c0 == null) { c0 = new SchedulePO { ProjectId = projectExists.Id, ScheduleIdentity = c.ScheduleIdentity, Cycle = c.Cycle, ScheduleTitle = c.ScheduleTitle, ScheduleLead = c.ScheduleLead, BeginDate = c.BeginDate, BeginTime = c.BeginTime, EndDate = c.EndDate, EndTime = c.EndTime, Weblink = c.Weblink, CreateTime = now, Valid = true, UpdateTime = now }; c0 = bllSchedule.Insert(c0, trans.DbConnection, trans.DbTrans); } else { c0.Cycle = c.Cycle; c0.ScheduleTitle = c.ScheduleTitle; c0.ScheduleLead = c.ScheduleLead; c0.BeginDate = c.BeginDate; c0.BeginTime = c.BeginTime; c0.EndDate = c.EndDate; c0.EndTime = c.EndTime; c0.Weblink = c.Weblink; c0.UpdateTime = now; bllSchedule.Update(c, c0, trans.DbConnection, trans.DbTrans); } } Utility.DataCache.Schedule.InitCache(projectExists.Id); } #endregion #endregion trans.Commit(); Logger.Info("处理完结"); } catch (Exception ex) { trans.RollBack(); Logger.Error(ex); } finally { trans.Dispose(); } return(account); }
public Account(AccountPO entity) { LoadData(entity); }