public static bool UpdateUserSubscription(int userSubscriptionID, bool subscribed)
    {
        MyFlixEntities db = new MyFlixEntities();

        UserSubscription us = db.UserSubscriptions.FirstOrDefault(u => u.UserSubscriptionID == userSubscriptionID);

        if (us != null)
        {
            if (subscribed)
            {
                us.SubscribedDate = DateTime.UtcNow;
            }
            else
            {
                us.SubscribedDate = null;
            }

            db.UserSubscriptions.Attach(us);
            db.Entry(us).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(true);
        }

        return(false);
    }
    public static bool LinkSubscription(int serviceProdiverID)
    {
        MyFlixEntities db = new MyFlixEntities();

        if (db.UserSubscriptions.Any(u => u.UserID == SessionHandler.UserID && u.ServiceProviderID == serviceProdiverID))
        {
            return(false);
        }
        else
        {
            UserSubscription us = new UserSubscription {
                UserID = SessionHandler.UserID, ServiceProviderID = serviceProdiverID, NewPayment = 9.99M, OldPayment = 10.99M, SubscribedDate = DateTime.UtcNow
            };
            db.UserSubscriptions.Add(us);
            db.SaveChanges();

            return(true);
        }
    }
Пример #3
0
    public static bool CreateAccount(string email, string password)
    {
        MyFlixEntities db = new MyFlixEntities();

        if (db.Users.Any(u => u.EmailAddress.ToLower().Equals(email.ToLower())))
        {
            return(false);
        }
        else
        {
            User user = new User
            {
                EmailAddress     = email,
                Password         = password,
                DateCreated      = DateTime.UtcNow,
                IsActive         = true,
                ProfilePhotoPath = "",
            };
            db.Users.Add(user);
            db.SaveChanges();

            return(true);
        }
    }