Beispiel #1
0
        public async Task <IActionResult> UploadFile(Resources resources)
        {
            UploadFileRequest request = new UploadFileRequest();

            request.FileName = resources.FileName;
            string fileName  = Path.GetFileNameWithoutExtension(resources.ImagePath.FileName);
            string extension = Path.GetExtension(resources.ImagePath.FileName);

            // fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            fileName = fileName + extension;
            Console.WriteLine(fileName);

            var currentuser = context.User.SingleOrDefault(x => x.Email == User.Identity.Name);

            request.FilePath    = "D:\\00\\" + fileName;
            resources.SubjectId = 1;
            resources.UserId    = currentuser.Id;

            //upload file on azure
            await service.UploadFileBlobAsync(request.FilePath, request.FileName);

            //save file data in db
            context.Add(resources);
            await context.SaveChangesAsync();

            return(RedirectToAction("ListResources", "Resources"));
        }
Beispiel #2
0
 public async Task <IActionResult> EditProfile(int id, [Bind("Id,Email,Password,Name,Semester,Branch,Role")] User model)
 {
     if (id != model.Id)
     {
         return(View("NotFound"));
     }
     if (ModelState.IsValid)
     {
         try
         {
             context.Update(model);
             await context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!UserExists(model.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction("ViewProfile", "Profile"));
     }
     return(View(model));
 }
Beispiel #3
0
        public async void add([FromBody] AddFolderRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Devices)
                              .Include(a => a.Folders)
                              .Where(a => a.AccountId == request.AccountId)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                foreach (var folder in request.Folders)
                {
                    dbContext.Folders.Add(folder);
                    account.Folders.Add(folder);

                    //await FirebaseHelper.SendMessage(account, "added_folder", folder);
                }

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

                if (account == null)
                {
                    return;
                }

                foreach (var blacklist in request.Blacklists)
                {
                    dbContext.Blacklists.Add(blacklist);
                    account.Blacklists.Add(blacklist);

                    await FirebaseHelper.SendMessage(account, "added_blacklist", new
                    {
                        id           = blacklist.DeviceId,
                        phone_number = blacklist.PhoneNumber,
                        phrase       = blacklist.Phrase
                    });
                }

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

                if (account == null)
                {
                    return;
                }

                var messages = account.Messages.Where(m => m.Timestamp < timestamp).ToList();

                foreach (var message in messages)
                {
                    dbContext.Messages.Remove(message);
                    account.Messages.Remove(message);
                }

                await FirebaseHelper.SendMessage(account, "cleanup_messages", new
                {
                    timestamp
                });

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #6
0
        public async void add([FromBody] AddContactRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Contacts)
                              .Where(a => a.AccountId == request.AccountId)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                foreach (var contact in request.Contacts)
                {
                    dbContext.Contacts.Add(contact);
                    account.Contacts.Add(contact);

                    await FirebaseHelper.SendMessage(account, "added_contact", new
                    {
                        phone_number = contact.PhoneNumber,
                        name         = contact.Name,
                        type         = contact.ContactType,
                        color        = contact.Color,
                        color_dark   = contact.ColorDark,
                        color_light  = contact.ColorLight,
                        color_accent = contact.ColorAccent
                    });
                }

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #7
0
        public async void update([FromQuery] string phone_number, [FromQuery] long device_id, [FromQuery] string account_id, [FromBody] UpdateContactRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, contact) = await GetContact(dbContext, device_id, account_id);

                if (contact == null)
                {
                    return;
                }

                contact.PhoneNumber = request.PhoneNumber;
                contact.Name        = request.Name;

                await FirebaseHelper.SendMessage(account, "updated_contact", new
                {
                    device_id    = device_id,
                    phone_number = contact.PhoneNumber,
                    name         = contact.Name,
                    type         = contact.ContactType,
                    color        = contact.Color,
                    color_dark   = contact.ColorDark,
                    color_light  = contact.ColorLight,
                    color_accent = contact.ColorAccent
                });

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

                if (message == null)
                {
                    return;
                }

                message.MessageType = request.Type;
                message.Read        = request.Read;
                message.Seen        = request.Seen;
                message.Timestamp   = request.Timestamp;

                await FirebaseHelper.SendMessage(account, "updated_message", new
                {
                    id   = message.DeviceId,
                    type = message.MessageType,
                    message.Read,
                    message.Seen,
                    timestamp = message.Timestamp
                });

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

                if (message == null)
                {
                    return;
                }

                message.To        = request.To;
                message.Data      = request.Data;
                message.MimeType  = request.MimeType;
                message.Timestamp = request.Timestamp;
                message.Title     = request.Title;
                message.Repeat    = request.Repeat;

                await FirebaseHelper.SendMessage(account, "updated_scheduled_message", new
                {
                    id        = message.DeviceId,
                    to        = message.To,
                    data      = message.Data,
                    mimeType  = message.MimeType,
                    timestamp = message.Timestamp,
                    title     = message.Title,
                    repeat    = message.Repeat
                });

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #10
0
        public async Task <IActionResult> Create(Course course)
        {
            if (course == null)
            {
                ViewBag.ErrorMessage = "Please Try Again.";
                return(View("NotFound"));
            }
            if (ModelState.IsValid)
            {
                context.Add(course);
                await context.SaveChangesAsync();

                return(RedirectToAction("ListCourses"));
            }
            return(View());
        }
        public async void remove(long device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Blacklists)
                              .Where(a => a.AccountId == account_id)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                var blacklist = account.Blacklists.Where(c => c.DeviceId == device_id).FirstOrDefault();
                if (blacklist == null)
                {
                    return;
                }

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

                dbContext.Blacklists.Add(blacklist);
                account.Blacklists.Add(blacklist);

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #12
0
        public async void add([FromBody] AddTemplateRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Templates)
                              .Where(a => a.AccountId == request.AccountId)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                foreach (var template in request.Templates)
                {
                    dbContext.Templates.Add(template);
                    account.Templates.Add(template);

                    //await FirebaseHelper.SendMessage(account, "added_template", template);
                }

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #13
0
        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();
            }
        }
Beispiel #14
0
        public async void add([FromBody] AddDraftRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Drafts)
                              .Where(a => a.AccountId == request.AccountId)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                foreach (var draft in request.Drafts)
                {
                    dbContext.Drafts.Add(draft);
                    account.Drafts.Add(draft);

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

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #15
0
        public async void update(long device_id, [FromQuery] string account_id, [FromBody] UpdateAutoReplyRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, autoReply) = await GetAutoReply(dbContext, device_id, account_id);

                if (autoReply == null)
                {
                    return;
                }

                autoReply.ReplyType = request.Type;
                autoReply.Pattern   = request.Pattern;
                autoReply.Response  = request.Response;

                await FirebaseHelper.SendMessage(account, "added_auto_reply", new
                {
                    device_id = autoReply.DeviceId,
                    type      = autoReply.ReplyType,
                    pattern   = autoReply.Pattern,
                    response  = autoReply.Response
                });

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #16
0
        public async void add([FromBody] AddAutoReplyRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.AutoReplies)
                              .Where(a => a.AccountId == request.AccountId)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                foreach (var autoReply in request.AutoReplies)
                {
                    dbContext.AutoReplies.Add(autoReply);
                    account.AutoReplies.Add(autoReply);

                    await FirebaseHelper.SendMessage(account, "added_auto_reply", new
                    {
                        device_id = autoReply.DeviceId,
                        type      = autoReply.ReplyType,
                        pattern   = autoReply.Pattern,
                        response  = autoReply.Response
                    });
                }

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

                if (account == null)
                {
                    return;
                }

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

                    await FirebaseHelper.SendMessage(account, "added_scheduled_message", new
                    {
                        id        = message.DeviceId,
                        to        = message.To,
                        data      = message.Data,
                        mimeType  = message.MimeType,
                        timestamp = message.Timestamp,
                        title     = message.Title,
                        repeat    = message.Repeat
                    });
                }

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #18
0
        public async void removeFromFolder(long device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(_, conversation) = await GetConversation(dbContext, device_id, account_id);

                if (conversation == null)
                {
                    return;
                }

                conversation.FolderId = -1L;

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #19
0
        public async void unarchive(long device_id, [FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(_, conversation) = await GetConversation(dbContext, device_id, account_id);

                if (conversation == null)
                {
                    return;
                }

                conversation.Archive = false;

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #20
0
        public async void update(long device_id, [FromQuery] string account_id, [FromBody] UpdateConversationRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(_, conversation) = await GetConversation(dbContext, device_id, account_id);

                if (conversation == null)
                {
                    return;
                }

                request.CloneTo(conversation);

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #21
0
        public async void remove(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;
                }

                dbContext.Conversations.Remove(conversation);
                account.Conversations.Remove(conversation);

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #22
0
        public async void update(long device_id, [FromQuery] string account_id, [FromBody] UpdateTemplateRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, template) = await GetTemplate(dbContext, device_id, account_id);

                if (template == null)
                {
                    return;
                }

                template.Text = request.Text;

                //await FirebaseHelper.SendMessage(account, "updated_template", template);

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #23
0
        public async void clear([FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Contacts)
                              .Where(a => a.AccountId == account_id)
                              .FirstOrDefaultAsync();

                var contacts = account.Contacts.ToArray();
                foreach (var contact in contacts)
                {
                    dbContext.Contacts.Remove(contact);
                    account.Contacts.Remove(contact);
                }
                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #24
0
        public async void update(long device_id, [FromQuery] string account_id, [FromBody] UpdateFolderRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var(account, folder) = await GetFolder(dbContext, device_id, account_id);

                if (folder == null)
                {
                    return;
                }

                folder.Name = request.Name;

                //await FirebaseHelper.SendMessage(account, "updated_folder", folder);

                await dbContext.SaveChangesAsync();
            }
        }
        public async void remove(int 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.DeviceId == id).FirstOrDefault();
                if (device == null)
                    return;

                dbContext.Devices.Remove(device);
                account.Devices.Remove(device);

                await dbContext.SaveChangesAsync();
            }
        }
Beispiel #26
0
        public async void add([FromBody] AddConversationRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                              .Include(a => a.Conversations)
                              .Where(a => a.AccountId == request.AccountId)
                              .FirstOrDefaultAsync();

                if (account == null)
                {
                    return;
                }

                foreach (var conversation in request.Conversations)
                {
                    dbContext.Conversations.Add(conversation);
                    account.Conversations.Add(conversation);

                    //await FirebaseHelper.SendMessage(account, "added_conversation", new
                    //{
                    //	id = conversation.DeviceId,
                    //	color = conversation.Color,
                    //	color_dark = conversation.ColorDark,
                    //	color_light = conversation.ColorLight,
                    //	color_accent = conversation.ColorAccent,
                    //	led_color = conversation.LedColor,
                    //	pinned = conversation.Pinned,
                    //	read = conversation.Read,
                    //	timestamp = conversation.Timestamp,
                    //	title = conversation.Title,
                    //	phone_numbers = conversation.PhoneNumbers,
                    //	snippet = conversation.Snippet,
                    //	ringtone = conversation.Ringtone,
                    //	id_matcher = conversation.IdMatcher,
                    //	mute = conversation.Mute,
                    //	archive = conversation.Archive,
                    //	folder_id = conversation.FolderId
                    //});
                }
                await dbContext.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> Register(User model)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = model.Email,
                    Email    = model.Email
                };


                //identity table user added
                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //   await signInManager.SignInAsync(user, isPersistent: false);


                    //my user table => user added
                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    var res = await userManager.AddToRoleAsync(user, model.Role);

                    if (res.Succeeded)
                    {
                        return(RedirectToAction("login", "account"));
                    }
                    foreach (var err in res.Errors)
                    {
                        ModelState.AddModelError("", err.Description);
                    }
                }

                foreach (var err in result.Errors)
                {
                    ModelState.AddModelError("", err.Description);
                }
            }

            return(View(model));
        }
		public async void remove(long device_id, [FromQuery] string android_device, [FromQuery] string account_id)
		{
			using (var dbContext = new PulseDbContext())
			{
				var (account, draft) = await GetDraft(dbContext, device_id, account_id);

				if (draft == null)
					return;

				dbContext.Drafts.Remove(draft);
				account.Drafts.Remove(draft);

				await FirebaseHelper.SendMessage(account, "removed_drafts", new
				{
					id = draft.DeviceId
				});

				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();
            }
        }
Beispiel #30
0
        public async void seen([FromQuery] string account_id)
        {
            using (var dbContext = new PulseDbContext())
            {
                var converstaions = await dbContext.Conversations
                                    .Where(a => a.AccountId == account_id)
                                    .FirstOrDefaultAsync();

                if (converstaions == null)
                {
                    return;
                }

                converstaions.Seen = true;

                //await FirebaseHelper.SendMessage(account, "seen_conversations", new {});

                await dbContext.SaveChangesAsync();
            }
        }