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 } }
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; } }
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); } }
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; } }
//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); } }
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(); } } }