public static bool Delete(int id) { using (var context = new eQueueContext()) { QueueInfo queue = context.Queues.Find(id); if (queue == null) { return(false); } context.Queues.Remove(queue); context.SaveChanges(); } return(true); }
/*user join the queue*/ public static void Insert(string nickname, int userId, int queueId) { using (var context = new eQueueContext()) { UserAccess access = new UserAccess { Nickname = nickname, AccessTypeName = AccessType.Default }; User user = context.Users.Find(userId); QueueInfo queue = context.Queues.Find(queueId); user.UserAccesses.Add(access); queue.UserAccesses.Add(access); access.User = user; access.QueueInfo = queue; context.UserAccesses.Add(access); context.SaveChanges(); } }
public static void Insert(int userId, int queueId) { using (var context = new eQueueContext()) { QueueOrder order = new QueueOrder { }; User user = context.Users.Find(userId); QueueInfo queue = context.Queues.Find(queueId); user.QueueOrders.Add(order); queue.QueueOrders.Add(order); order.User = user; order.QueueInfo = queue; order.Number = GetLastNumberInQueue(queue, context) + 1; context.QueueOrders.Add(order); context.SaveChanges(); } }
/*create new QueueInfo and UserAcces with info about queue's owner*/ public static QueueInfo Insert(string queueName, string link, DateTime?timer, int ownerId) { using (var context = new eQueueContext()) { var queue = new QueueInfo { Name = queueName, Link = link, Timer = timer }; var owner = context.Users.Find(ownerId); var access = new UserAccess { Nickname = owner.Login, AccessTypeName = AccessType.Owner, User = owner, QueueInfo = queue }; context.Queues.Add(queue); context.UserAccesses.Add(access); context.SaveChanges(); return(queue); } }
public static int GetLastNumberInQueue(QueueInfo queue, eQueueContext context) { return(context.QueueOrders.Where(qo => qo.QueueInfoId == queue.Id).Select(qo => qo.Number).DefaultIfEmpty(0).Max()); }