示例#1
0
        public int CreateEvent(string loginedUserId, Event @event, int timeOffset)
        {
            var(dataUser, dataCalendar) = serviceHelper.IsUserHasAccessToCalendar(loginedUserId, @event.CalendarId);
            if (dataCalendar != null)
            {
                if ([email protected](DateTimeKind.Utc))
                {
                    @event.Start  = @event.Start.AddMinutes(timeOffset);
                    @event.Finish = @event.Finish.AddMinutes(timeOffset);
                }

                Data.Models.Event dataEvent = Mapper.Map <Event, Data.Models.Event>(@event);
                dataEvent.CreatorId = dataUser.IdUser;
                int eventId = serviceHelper.WrapMethodWithReturn(() => eventRepos.CreateEvent(dataEvent), -1);
                if (eventId > 0)
                {
                    if (@event.Notify != null && @event.Notify.Value > 0)
                    {
                        notificationRepos.CreateNotification(eventId, @event.Notify.Value, (int)@event.Notify.TimeUnit);
                    }
                }
                return(eventId);
            }
            return(-1);
        }
示例#2
0
        public async Task <string> Toggle(int postId)
        {
            var user = await _db.Users.FirstOrDefaultAsync(u => u.UserName == User.Identity.Name);

            var post = await _db.Posts.FirstOrDefaultAsync(p => p.Id == postId);

            var like = await _db.Likes.FirstOrDefaultAsync(l => l.Post.Id == postId && l.User.UserName == User.Identity.Name);

            if (like == null)
            {
                // Not yet liked, add new like
                var newLike = new Like
                {
                    Post      = post,
                    Timestamp = DateTime.Now,
                    User      = user
                };

                _db.Likes.Add(newLike);

                var notification = await _notificationService.CreateNotification(post.User.UserName, User.Identity.Name, string.Format("{0} has liked your post.", User.Identity.Name));

                await _notificationService.SendNotification(notification);
            }
            else
            {
                // Already liked post, unlike it
                _db.Likes.Remove(like);
            }

            await _db.SaveChangesAsync();

            return(String.Empty);
        }
示例#3
0
        public async Task CheckProximityAsync(double currentLatitude, double currentLongitude)
        {
            var products = await groceryService.GetProductsNotBought();

            foreach (var prod in products)
            {
                double distance = calculateDistance(currentLatitude, currentLongitude, prod.Lat, prod.Lon);
                if (distance <= MIN_DISTANCE)
                {
                    string listName = await groceryService.GetListNameById(prod.ListId);

                    notification.CreateNotification("GroceryList", $"List: {listName}; {string.Format("{0:N2}", distance)}km distance from product: {prod.Name}");
                }
            }
        }
 public Task ShowNotification(INotification notification)
 {
     return(dispatcher.InvokeAsync(() => toastNotifier.Show(notification.CreateNotification())).Task);
 }