Ejemplo n.º 1
0
 public IEnumerable<ApiSubscription> GetSubscriptions()
 {
     using (serviceEntities container = new serviceEntities())
     {
         foreach (var sub in container.Subscriptions)
         {
             yield return new ApiSubscription(sub);
         }
     }
 }
Ejemplo n.º 2
0
 public IEnumerable<ApiSubscription> GetUserSubscriptions(int userId)
 {
     using (serviceEntities container = new serviceEntities())
     {
         var user = container.Users.Find(userId);
         if (user == null)
         {
             throw new FaultException("No such user");
         }
         foreach (var sub in user.Subscriptions)
         {
             yield return new ApiSubscription(sub);
         }
     }
 }
Ejemplo n.º 3
0
 public ApiSubscription AddUserSubscription(int userId, ApiSubscription subscription)
 {
     using (serviceEntities container = new serviceEntities())
     {
         //Utilities.toUrlFriendlyIndentifier(subscription.Name);
         var user = container.Users.Find(userId);
         if (user == null)
         {
             throw new ArgumentNullException("No such user");
         }
         subscription.UrlFriendly = Utilities.toUrlFriendlyIndentifier(subscription.Name);
         user.Subscriptions.Add(subscription.ToEntity());
         container.SaveChanges();
         return subscription;
     }
 }
Ejemplo n.º 4
0
 public void DeleteSubscription(Guid subscriptionId)
 {
     using (serviceEntities container = new serviceEntities())
     {
         try
         {
             var sub = container.Subscriptions.Find(subscriptionId);
             container.Subscriptions.Remove(sub);
             container.SaveChanges();
         }
         catch (Exception)
         {
             //todo add logging
         }//if its there its already deleted
     }
 }
Ejemplo n.º 5
0
 public ApiSubscription UpdateSubscription(ApiSubscription subValues)
 {
     using (serviceEntities container = new serviceEntities())
     {
         var sub = container.Subscriptions.Find(subValues.Id);
         if (sub == null)
         {
             throw new FaultException("No such subscription");
         }
         sub.Name = subValues.Name;
         sub.Price = subValues.Price;
         sub.PriceIncVatAmount = subValues.PriceIncVatAmount;
         sub.UrlFriendly = Utilities.toUrlFriendlyIndentifier(subValues.Name);
         container.SaveChanges();
         return new ApiSubscription(sub);
     }
 }
Ejemplo n.º 6
0
        public int AddUser(ApiUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            var entityUser = user.ToEntity();

            using (serviceEntities container = new serviceEntities())
            {

                //If I where to use url-friendly-name I would have done this or maybe have a unique contstraint on the colmn and then add the count in the catch:
                    //int count = container.Users.Where(u => u.FirstName == entityUser.FirstName && u.LastName == entityUser.LastName).Count();
                    //entityUser.urlFriendly = Utilities.toUrlFriendlyIndentifier(entityUser.FirstName + "-" + entityUser.LastName);
                    //entityUser.urlFriendly += count > 0 ? count.ToString() : "";
                    container.Users.Add(entityUser);
                    container.SaveChanges();
                    return entityUser.Id;
            }
        }
Ejemplo n.º 7
0
 //public IEnumerable<ApiSubscription> GetSubscriptions()
 //{
 //    using (rebtelEntities container = new rebtelEntities())
 //    {
 //        foreach (var sub in container.Subscriptions)
 //        {
 //            yield return new ApiSubscription(sub);
 //        }
 //    }
 //}
 public ApiUser UpdateUser(ApiUser userValues)
 {
     using (serviceEntities container = new serviceEntities())
     {
         var user = container.Users.Find(userValues.Id);
         if (user == null)
         {
             throw new FaultException("No such user to update");
         }
         user.FirstName = userValues.FirstName;
         user.LastName = userValues.LastName;
         user.Email = userValues.Email;
         container.SaveChanges();
         return new ApiUser(user);
     }
 }
Ejemplo n.º 8
0
 public IEnumerable<ApiUser> GetUsers()
 {
     using (serviceEntities container = new serviceEntities())
     {
         foreach (var user in container.Users.Include("Subscriptions"))
         {
             yield return new ApiUser(user);
         }
     }
 }
Ejemplo n.º 9
0
 public ApiUser GetUser(int userId)
 {
     using (serviceEntities container = new serviceEntities())
     {
         var user = container.Users.Find(userId);
         if (user == null)
         {
             throw new FaultException("No such user");
         }
         return new ApiUser(user);
     }
 }
Ejemplo n.º 10
0
 public void DeleteUser(int userId)
 {
     using (serviceEntities container = new serviceEntities())
     {
         User user = container.Users.Find(userId);  //Where(u => u.urlFriendly == urlFriendlyname).FirstOrDefault();
         if (user != null)
         {
             container.Users.Remove(user);
             container.SaveChanges();
         }
     }
 }