public Cart Create(Cart entity, User user, List <CartItem> items) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (!entity.Validate()) { throw new ValidationException(entity.ValidationResults); } Cart createdEntity = null; using (IUnitOfWork uow = RepositoryFactory.CreateUnitOfWork()) { createdEntity = repository.Create(entity); CartOwner cartOwner = CartOwner.Create(createdEntity, user); double cartIndex = CartOwnerMobileService.Obj.GetLastIndex(user.Id); cartOwner.SetCartIndex(cartIndex); cartOwner = CartOwnerMobileService.Obj.Create(cartOwner); ItemMobileService.Obj.MultipleCreate(items, createdEntity.CartId); uow.Complete(); } if (createdEntity == null) { throw new RepositoryException("Entity not created"); } Tracer.Log.EntityCreated(nameof(Cart), createdEntity.CartId); return(createdEntity); }
public IHttpActionResult GetAccess([FromBody] GetAccessBindingModel model) { int[] parameters = UserCodeOperation.DecodeCode(model.Id); int cartId = parameters[0]; AccessLevel accessLevel = (AccessLevel)parameters[1]; User user = GetCurrentUser(); FriendService.Obj.CreateFriends(user.Id, cartId); Cart cart = CartMobileService.Obj.GetById(cartId); CartOwner currentCartUser = CartOwnerMobileService.Obj.GetCartUser(cartId, user.Id); if (currentCartUser != null) { if (currentCartUser.AccessLevel == AccessLevel.Owner) { CartIndexBindingModel earlyBindingModel = getCartIndexBindingModel(cart); return(Ok(earlyBindingModel)); } } CartOwner cartOwner = CartOwner.Create(cart, user, accessLevel); double cartIndex = CartOwnerMobileService.Obj.GetLastIndex(user.Id); cartOwner.SetCartIndex(cartIndex); CartOwnerMobileService.Obj.Create(cartOwner); CartIndexBindingModel bindingModel = getCartIndexBindingModel(cart); return(Ok(bindingModel)); }