コード例 #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 ActionResult GetAccess(string id)
        {
            try
            {
                int[] parameters = UserCodeOperation.DecodeCode(id);

                int         cartId      = parameters[0];
                AccessLevel accessLevel = (AccessLevel)parameters[1];

                if (accessLevel == AccessLevel.Owner)
                {
                    throw new BusinessRuleException("Owner access level must not be selected");
                }

                User user = GetCurrentUser();

                CartOwner currentCartUser = CartOwnerService.Obj.GetCartUser(cartId, user.Id);

                if (currentCartUser != null)
                {
                    if (currentCartUser.AccessLevel == AccessLevel.Owner)
                    {
                        return(RedirectToAction("Index"));
                    }
                }

                FriendService.Obj.CreateFriends(user.Id, cartId);

                Cart cart = CartService.Obj.GetById(cartId);

                CartOwner cartOwner = CartOwner.Create(cart, user, accessLevel);

                CartOwnerService.Obj.Create(cartOwner);

                return(RedirectToAction("Index"));
            }

            catch (Exception ex)
            {
                TempData["ErrorMessage"] = ex.Message;

                return(RedirectToAction("Login", "Account"));
            }
        }
コード例 #4
0
        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));
        }
コード例 #5
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));
        }