Exemplo n.º 1
0
        public async Task<ValidationResult> ShareCalendar(ShareDetails model)
        {
            try
            {
                //Parse guid
                Guid? guid = ParseGuid(model.CalendarId);
                if (guid == null) return AddError("Unable to parse calendarId");

                //Check calendar exists
                var cal = await _calendarRepo.Get(x => x.Id == guid.Value)
                    .Include(x => x.Owner).FirstOrDefaultAsync();

                if (cal == null)
                    return AddError("Calendar was not found");

                //Check if the recipient is a member of the app
                var user = await _userRepo.Get(x => x.Email == model.Email).FirstOrDefaultAsync();

                //If this user isn't registered send invite email
                if (user == null)
                {
                    await SendInvitationEmail(model);
                    Result.Success = true;
                    return Result;
                }
                
                //Check for an existing calendar invitation
                Invitation existingInvitation = await _invitationService.CheckForDuplicates(user.Id, model.SenderUserId, guid.Value, null);

                if (existingInvitation != null)
                    return AddError("An invitation matching the specified values already exists");

                //Assuming we have a registered user and no existing invitation, create a new one
                Invitation inv = new Invitation
                {
                    CalendarId = guid.Value,
                    RecipientId = user.Id,
                    SenderId = model.SenderUserId,
                    TypeId = (int)LookUpEnums.InvitationTypes.Calendar,
                    DisplayMessage = $"{cal.Owner.Name} has invited you to share their calendar \"{cal.Name}\""
                };

                await _invitationService.AddInvitation(inv);
                
                //Finally send out GCM notification
                string message = $"{cal.Owner.Name} wants to share their Calendar";

                //Send the notification
                AndroidGCMPushNotification.SendNotification(user.DeviceId, message);

                Result.Success = true;
                return Result;
            }
            catch (Exception ex)
            {
                Result.Error = ex.Message;
                return Result;
            }
        }
        /// <summary>
        /// Share an event with a single specified user
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<IHttpActionResult> Event(ShareDetails model)
        {
            if(model.EventId == null) ModelState.AddModelError("EventId", "EventId is required");

            if (!ModelState.IsValid) { return BadRequest("Missing required information"); }

            var result = await _shareService.ShareEvent(model);

            if (result.Success)
            {
                return Ok();
            }

            return BadRequest(result.Error);
        }
Exemplo n.º 3
0
        private async Task<bool> SendInvitationEmail(ShareDetails model)
        {
            User sender = await _userRepo.GetByIdAsync(model.SenderUserId);
            if (sender == null) return false;

            string type = model.CalendarId != null ? "calendar" : "event";
            string subject = $"{sender.Name} has invited to share their {type} with you!";
            StringBuilder emailBody = new StringBuilder();

            emailBody.Append("Hey!\n\n");
            emailBody.Append($"Your friend {sender.Name} has invited you to join and share their {type} on What's Up!\n\n");
            emailBody.Append($"You can accept this invitation and view the {type} on the What's Up application.\n\n");
            emailBody.Append("Open the following link on your android mobile device to proceed: \n\n");
            emailBody.Append("---------------------------------------------------------------------------------------------\n");
            emailBody.Append("[ DEEPLINK HERE ]\n");
            emailBody.Append("---------------------------------------------------------------------------------------------\n\n");
            emailBody.Append("See you soon!\n\n");
            emailBody.Append("What's Up Team");



            EmailHelper email = new EmailHelper();
            email.AddToAddress(model.Email);
            email.SetSubject(subject);
            email.SetBody(emailBody.ToString());

            return await email.Send();
        }