コード例 #1
0
        public async Task <IHttpActionResult> MakeSharing(ShareBindingModel model)
        {
            string userCode = UserCodeOperation.ProduceCode(model.CartId, (int)model.AccessLevel);

            foreach (var email in model.Emails)
            {
                User user = UserService.Obj.FindByEmail(email);

                if (user != null)
                {
                    Cart cart = CartMobileService.Obj.GetById(model.CartId);

                    CartOwner cartOwner = CartOwner.Create(cart, user, AccessLevel.ReadWrite);

                    CartOwnerMobileService.Obj.Create(cartOwner);

                    await UserService.Obj.SendEmailToShareCard(user.Email, userCode);
                }

                else
                {
                    await UserService.Obj.SendEmailToShareCard(email, userCode);
                }
            }

            var users = CartOwnerMobileService.Obj.GetUsersByCart(model.CartId).Select(x => x.ToUserProfileBindingModel(UserService.Obj.FindById(x.UserId), ImageService.Obj.FindByUserId(x.UserId))).ToList();

            return(Ok(users));
        }
コード例 #2
0
        public ActionResult GenerateShareUrl(GenerateSharingUrlViewModel model)
        {
            string codedUrl = UserCodeOperation.ProduceCode(new int[] { model.CartId, (int)model.AccessLevel });

            string rootUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));

            string fullUrl = $"{rootUrl}Cart/GetAccess/{codedUrl}";

            return(Json(fullUrl, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public async Task <IHttpActionResult> CreateCard(CreateCartBindingModel model)
        {
            User user = GetCurrentUser();

            Cart cart = null;

            if (!model.CartId.HasValue)
            {
                cart = Cart.Create(model.Title, model.Notes, model.Date);

                List <CartItem> items = model.Items?.Select(x => CartItem.Create(cart, Item.Create(x.Title, user), x.Status.Value)).ToList();

                cart = CartMobileService.Obj.Create(cart, user, items);

                // Make Sharing

                if (model.Users?.Count != 0 && model.Users != null)
                {
                    string userCode = UserCodeOperation.ProduceCode(cart.CartId, (int)AccessLevel.ReadWrite);

                    List <string> emails = model.Users.Select(x => x.Email).ToList();

                    User userToFind = null;

                    foreach (var email in emails)
                    {
                        if (email != user.Email)
                        {
                            userToFind = UserService.Obj.FindByEmail(email);

                            if (userToFind != null)
                            {
                                Cart cartToFind = CartMobileService.Obj.GetById(cart.CartId);

                                CartOwner cartOwner = CartOwner.Create(cartToFind, userToFind, AccessLevel.ReadWrite);

                                CartOwnerMobileService.Obj.Create(cartOwner);

                                await UserService.Obj.SendEmailToShareCard(userToFind.Email, userCode);
                            }

                            else
                            {
                                await UserService.Obj.SendEmailToShareCard(email, userCode);
                            }
                        }
                    }
                }
            }

            else
            {
                cart = CartMobileService.Obj.GetById(model.CartId.Value);
                cart.Update(model.Title, model.Notes, model.Date);

                List <CartOwner> users = new List <CartOwner>();

                if (model.Users != null)
                {
                    users = model.Users.Select(x => CartOwner.Create(cart, UserService.Obj.FindById(x.UserId), x.AccessLevel)).ToList();
                }

                List <CartItem> items = model.Items?.Select(x => CartItem.Create(cart, Item.Create(x.Title, user), x.Status.Value)).ToList();

                users.Add(CartOwner.Create(cart, user, AccessLevel.Owner));

                CartMobileService.Obj.Update(cart, items, users);
            }

            CartIndexBindingModel bindingModel = getCartIndexBindingModel(cart);

            return(Ok(bindingModel));
        }