示例#1
0
        public void AddShare(ShareDTO share, StatisticsDTO statistics)
        {
            var ns = Mapper.Map <Share>(share);

            repo.Add(ns);
            statistics.InsertsTime += repo.LastOperationTime;
            statistics.InsertsCount++;
        }
示例#2
0
        public int RegisterShare(ShareRegistrationInfo shareInfo)
        {
            var shareToAdd = new ShareEntity()
            {
                ShareName = shareInfo.Name,
                ShareCost = shareInfo.Cost
            };

            sharesRepository.Add(shareToAdd);
            sharesRepository.SaveChanges();

            return(shareToAdd.ShareID);
        }
        public ActionResult Share(string id, [FromBody] ShareViewModel model)
        {
            var ownerId = HttpContext.User.Identity.Name;

            if (!storyRepository.IsOwner(id, ownerId))
            {
                return(Forbid("You are not the owner of this story"));
            }

            var userToShare = userRepository.GetSingle(u => u.Username == model.Username);

            if (userToShare == null)
            {
                return(BadRequest(new { username = "******" }));
            }
            var owner = userRepository.GetSingle(s => s.Id == ownerId);
            var story = storyRepository.GetSingle(s => s.Id == id, s => s.Shares);

            if (story.OwnerId == ownerId)
            {
                return(BadRequest(new { username = "******" }));
            }

            var existingShare = story.Shares.Find(l => l.UserId == userToShare.Id);

            if (existingShare == null)
            {
                shareRepository.Add(new Share
                {
                    UserId  = userToShare.Id,
                    StoryId = id
                });
                shareRepository.Commit();
                hubContext.Clients.User(userToShare.Id).SendAsync(
                    "notification",
                    new Notification <ShareRelatedPayload>
                {
                    NotificationType = NotificationType.SHARE,
                    Payload          = new ShareRelatedPayload
                    {
                        Username   = owner.Username,
                        StoryTitle = story.Title
                    }
                }
                    );
            }
            return(NoContent());
        }