Exemplo n.º 1
0
        public async void remove(long device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, autoReply) = await GetAutoReply(dbContext, device_id, account_id);

                if (autoReply == null)
                {
                    return;
                }

                dbContext.AutoReplies.Remove(autoReply);
                account.AutoReplies.Remove(autoReply);

                //await FirebaseHelper.SendMessage(account, "removed_auto_reply", new
                //{
                //	id = autoReply.DeviceId
                //});

                await dbContext.SaveChangesAsync();
            }
        }
        public async Task <SignupResponse> signup([FromBody] SignupRequest request)
        {
            var account = new Account();

            account.AccountId    = Guid.NewGuid().ToString("N");
            account.Salt1        = Crypto.GenerateSalt();
            account.Salt2        = Crypto.GenerateSalt();
            account.PasswordHash = Crypto.GetPasswordHash(request.Password, account.Salt1);

            account.Username    = request.Username;
            account.RealName    = request.RealName;
            account.PhoneNumber = request.PhoneNumber;

            using (var dbContext = new PulseDbContext())
            {
                await dbContext.Accounts.AddAsync(account);

                await dbContext.SaveChangesAsync();
            }

            return(account.ForceType <SignupResponse>());
        }
        public async void remove(long contact_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, contact) = await GetContactById(dbContext, contact_id, account_id);

                if (contact == null)
                {
                    return;
                }

                dbContext.Contacts.Remove(contact);
                account.Contacts.Remove(contact);

                //await FirebaseHelper.SendMessage(account, "removed_contact_by_id", new
                //{
                //	id = contact_id,
                //});

                await dbContext.SaveChangesAsync();
            }
        }
        public async void remove(long device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, folder) = await GetFolder(dbContext, device_id, account_id);

                if (folder == null)
                {
                    return;
                }

                dbContext.Folders.Remove(folder);
                account.Folders.Remove(folder);

                await FirebaseHelper.SendMessage(account, "removed_folder", new
                {
                    id = device_id
                });

                await dbContext.SaveChangesAsync();
            }
        }
        public async void add([FromBody] AddMessagesRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Messages)
                              .Where(a => a.AccountId == request.AccountId)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                foreach (var message in request.Messages)
                {
                    dbContext.Messages.Add(message);
                    account.Messages.Add(message);

                    await FirebaseHelper.SendMessage(account, "added_message", new
                    {
                        id             = message.DeviceId,
                        conversationId = message.DeviceConversationId,
                        type           = message.MessageType,
                        timestamp      = message.Timestamp,
                        read           = message.Read,
                        seen           = message.Seen,
                        sent_device    = message.SentDevice,
                        data           = message.Data,
                        mime_type      = message.MimeType,
                        from           = message.MessageFrom,
                        color          = message.Color
                    });
                }

                await dbContext.SaveChangesAsync();
            }
        }
        public async Task <ContactsSimpleResponse[]> simple([FromQuery] string account_id, [FromQuery] int limit, [FromQuery] int offset)
        {
            using (var dbContext = new PulseDbContext())
            {
                // TODO: Change this to only select PhoneNumber, Name, Id, IdMatcher, Color, ColorAccent, ContactType
                var account = await dbContext.Accounts
                              .Include(a => a.Contacts)
                              .Where(a => a.AccountId == account_id)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return(new ContactsSimpleResponse[0]);
                }

                var contacts = account.Contacts.Select(a => new ContactsSimpleResponse {
                    PhoneNumber = a.PhoneNumber,
                    Name        = a.Name,
                    Id          = a.Id,
                    IdMatcher   = a.IdMatcher,
                    Color       = a.Color,
                    ColorAccent = a.ColorAccent,
                    ContactType = a.ContactType
                }).ToArray();

                if (offset > 0)
                {
                    contacts = contacts.Skip(offset).ToArray();
                }

                if (limit > 0)
                {
                    contacts = contacts.Take(limit).ToArray();
                }

                return(contacts);
            }
        }
Exemplo n.º 7
0
        public async void seen(long device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, conversation) = await GetConversation(dbContext, device_id, account_id);

                if (conversation == null)
                {
                    return;
                }

                conversation.Seen = true;

                //await FirebaseHelper.SendMessage(account, "read_conversation", new
                //{
                //	id = device_id,
                //	android_device,
                //	account_id
                //});

                await dbContext.SaveChangesAsync();
            }
        }
Exemplo n.º 8
0
        public async void remove([FromQuery] string phone_number, [FromQuery] long device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, contact) = await GetContact(dbContext, device_id, account_id);

                if (contact == null)
                {
                    return;
                }

                dbContext.Contacts.Remove(contact);
                account.Contacts.Remove(contact);

                await FirebaseHelper.SendMessage(account, "removed_contact", new
                {
                    device_id    = device_id,
                    phone_number = phone_number,
                });

                await dbContext.SaveChangesAsync();
            }
        }
		public async void update(long device_id, [FromQuery] string account_id, [FromBody] UpdateDraftRequest request)
		{
			using (var dbContext = new PulseDbContext())
			{
				var (account, draft) = await GetDraft(dbContext, device_id, account_id);

				if (draft == null)
					return;

				draft.Data = request.Data;
				draft.MimeType = request.MimeType;

				await FirebaseHelper.SendMessage(account, "replaced_drafts", new
				{
					id = draft.DeviceId,
					conversation_id = draft.DeviceConversationId,
					data = draft.Data,
					mime_type = draft.MimeType
				});

				await dbContext.SaveChangesAsync();
			}
		}
        public async void updatePrimary([FromQuery] string new_primary_device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Devices)
                              .Where(a => a.AccountId == account_id)
                              .FirstOrDefaultAsync();

                var device = account.Devices.Where(d => d.Primary).FirstOrDefault();
                if (device != null)
                {
                    device.Primary = false;
                }

                device = account.Devices.Where(d => d.DeviceId == long.Parse(new_primary_device_id)).FirstOrDefault();
                if (device != null)
                {
                    device.Primary = true;
                }

                await dbContext.SaveChangesAsync();
            }
        }
        public async void remove([FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Devices)
                              .Where(a => a.AccountId == account_id)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                //await FirebaseHelper.SendMessage(account, "removed_account", new
                //{
                //	id = account_id
                //});

                dbContext.Accounts.Remove(account);

                await dbContext.SaveChangesAsync();
            }
        }
        public async void updateSetting([FromQuery] string account_id, [FromQuery] string pref, [FromQuery] string type, [FromQuery] string value)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Where(a => a.AccountId == account_id)
                              .FirstOrDefaultAsync();

                if (account != null)
                {
                    switch (pref)
                    {
                    case "base_theme":
                        account.BaseTheme = value;
                        break;

                    case "apply_primary_color_toolbar":
                        account.ApplyPrimaryColorToToolbar = bool.Parse(value);
                        break;

                    case "global_primary_color":
                        account.ColorLight = int.Parse(value);
                        break;

                    case "global_primary_dark_color":
                        account.ColorDark = int.Parse(value);
                        break;

                    case "global_accent_color":
                        account.ColorAccent = int.Parse(value);
                        break;

                    case "apply_theme_globally":
                        account.UseGlobalTheme = bool.Parse(value);
                        break;

                    case "conversation_categories":
                        account.ConversationCategories = bool.Parse(value);
                        break;

                    case "message_timestamp":
                        account.MessageTimestamp = bool.Parse(value);
                        break;

                    case "bubble_style":
                        account.RounderBubbles = value == "circle";
                        break;

                    default:
                        Console.WriteLine(pref);
                        break;
                    }

                    //await FirebaseHelper.SendMessage(account, "update_setting", new
                    //{
                    //	pref,
                    //	type,
                    //	value
                    //});

                    await dbContext.SaveChangesAsync();
                }
            }
        }
 public TimeTableController(PulseDbContext context, UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager)
 {
     this.context       = context;
     this.userManager   = userManager;
     this.signInManager = signInManager;
 }
Exemplo n.º 14
0
 public CourseController(PulseDbContext context, UserManager <IdentityUser> userManager)
 {
     this.context     = context;
     this.userManager = userManager;
 }
Exemplo n.º 15
0
 public ResourcesController(IUploadAzureService service, PulseDbContext context)
 {
     this.service = service;
     this.context = context;
 }