Notify user if their search criteria are met - c#

I developing a sale system using asp.net mvc. My search system allows users to save their search criteria and will notify them by email when a new product is posted is met their criteria. I tried the following:
The first way: Create a function to send bulk mail through gmail and I put this function in the post function. You can see the code described below to understand what I said:
public ActionResult PostProduct()
{
....
var list = Check(); // get a list of user email when their search criteria are met with the posted product
Send(list); // send email to the list
// I don't know how long does it take to complete this function?
}
However, this method requires a lot of resources from the server and takes a lot of time to respond (if the number of emails up to 1000, it would be a bad thing), but I can customize the parameters into email content (such as links, images, ...)
The second way: I used a mail service (MailChimp) and I called its API successfully, sending mail seems easy but I can not adjust the input parameters. That means I can not customize the content of my email.
I would like to ask people if there is a better and wiser way of doing things than I used to. Thank for reading

Related

Find All Available Meeting Rooms using Microsoft.Office.Interop.Outlook

I was developing one application where I want to retrieve the available rooms from the "All Rooms" of the outlook address book. I am able to retrieve all the room entries from "All Rooms" Address Entry List. And then able to search for individual room's availability by calling AddressEntry.GetFreeBusy().
But the problem I am facing is the time performance of the code. If the number of rooms is high(let's say 500) then the time take to search availability of the room(worst case scenario where available room locates near to last of the list) is very high.
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application()
var allRooms = app.Session.AddressLists["All Rooms"].Cast<Microsoft.Office.Interop.Outlook.AddressEntry>().ToLis();
DateTime today = DateTime.Today;
foreach(var room in allRooms)
{
//the below function will return the room status in a string of 1&0 for an interval of 1 min
string status = room.GetFreeBusy(today, 1, true); //sequentially calling this method is costly. What improvement can I do here?
//process the status and make some if free for certain time period add to list of available list
}
The GetFreeBusy method accepts three parameters and the default value for the MinPerChar parameter is 30 minutes. But your code only checks the first minute of the appointment. You need to go over the whole duration of your meeting (at least 30 minutes). Take a look at the similar forum thread.
If you are a .Net Developer then use Microsoft Graph APIs for this purpose. I used
POST /me/calendar/getSchedule
POST /users/{id|userPrincipalName}/calendar/getSchedule
from to achieve this. You can login as your userid and use ME option or you can use application mode login to login and use {id|userPrincipalName} to get calendar details for a room.
This link provides the basics on how to login and have good examples for Graph in general.
https://developer.microsoft.com/en-us/graph/graph-explorer
Ref:
https://learn.microsoft.com/en-us/graph/api/calendar-getschedule?view=graph-rest-1.0&tabs=http

How can I hold data through multiple Web pages

Starting at WebPage1, the user enters some data into a textbox and performs a search based on that search data. Then the user navigates away from WebPage1 to WebPage2 via a link.
How can I maintain their original search data when the user returns to WebPage1?
The user does not want to see the data in a query string. However the data is not sensitive, and any data from the client will be handled before processing.
We are using C# Mvc framework with Razor.
I have been trying to Post the entire model each time rather than using Get requests. However, this is not working well and does not follow a simple Post-Redirect-Get pattern more like Post-Redirect-Post.
You can use sessions to pass data from one webpage to another until you close the browser here is an example
//assuming the method below will return list of Products
var products=Db.GetProducts();
//Store the products to a session
Session["products"]=products;
//To get what you have stored to a session
var products=Session["products"] as List<Product>;
//to clear the session value
Session["products"]=null;

Google Spreadsheet API, Multiple User, Adding new row and Updating row at same time

So i just recently able to play with google spreadsheet API,
i intend to use it as my C# apps database, so people can use either web (via docs) or desktop (via C#).
There are 1 problem that i'm afraid of: Will there conflict if 2 people are doing inserting + updating.
Scenario:
There are 2 user,
A will be in charge of adding new row
B will be in charge of reviewing A work and putting comment.
Both A and B will working at the same time.
Conflict I'm afraid of:
When B using the apps to update comment, the apps will get the data and have the row ranges, let say A100:H100, Then A proceed to add data.
I'm afraid that if the data is added above A100:H00, then when the apps submit changes from B, it will not placed in correct row.
Is there anyway to avoid this?
Yes, you can Add and update at the same time by using Google Sheets API. batchUpdate would be the best method to work by taking one or more request objects, each one specifying a single kind of request to perform.
When updating a spreadsheet, some kinds of requests may return responses. These are returned in an array, with each response occupying the same index as the corresponding request. Some requests do not have responses. For those requests, the response will be empty.
Typically the "Add" requests will have responses, so that you know information (such as the ID) of the newly added object. See Response for the list of supported responses.
Sample update from response:
{
// Union field kind can be only one of the following:
"addNamedRange": {
object(AddNamedRangeResponse)
},
"addSheet": {
object(AddSheetResponse)
},
"addFilterView": {
object(AddFilterViewResponse)
},

Send Birthday Emails to Employees MVC ASP.net

I'm trying to create a function where I send Email to a user when it their birthday. I have all their personal data in my database, so I just wonder like where do i start? Or what do i do? I'm creating this in an MVC app. This is what I've done so far.
This is my function in my repository.
public List<Employee> GetEmployeesBasesOnBirthDate(int customerId, string birthdate)
{
return db.Employees.Where(x => x.CustomerId == customerId && x.BirthDate.Contains(birthdate)).ToList();
}
And this is what i do in my Controller
public ActionResult BirthdayEmail()
{
var repository = new SiteRepository();
var employeebirthday = repository.GetEmployeesBasesOnBirthDate(CommonHelper.CustomerId, DateTime.Now.ToString());
return View();
}
What do I do now?
You can create a method which automatically send Emails on their birthdays.
using System.Net.mail; includes a method for mailmessage you can use it to make you mail message body and use your database data to send mail templets to your Employees.
I know it's not the complete solution but if you do little more search on mail templates you will get solution for your code.
Hope it helps.
You could change your method GetEmployeesBasesOnBirthDate(int customerId, DateTime birthdate)
And then compare dates, do you need exact time or dates only ?
After that you should loop trough employee list and send email.
I'm guessing you'll want to send out the emails in an asynchronous fashion rather than from an action method. If that is the case, you will need a background job that:
gets fired automatically in the morning
retrieves the list of employees that were born on that day
actually sends out the emails
For asynchronous jobs you want to look into Hangfire which, among other things, lets you set up recurring tasks. Moreover, its documentation also includes a tutorial teaching you how to send mail.
This could be a sound architecture, but if you need more specific answers you'll need to post specific questions.
Note: the fact that dates are stored as strings in the db will cause a lot of grief and ugly parsing all over the place. If at all possible change that to use an actual date type.

I don't understand how email activation works

I want to verify that the user email is valid and turn this email into his id in my system.
Yet I don't know how to make a link in the mail, that activates the account like(facebook and others
) and I don't really understand what happens when the link is selected.
I thought of generating a key like "sdklbsdgk4493" to enter once- so that guessing is hard, yet for many people copy and paste is not trivial and I may annoy them with this solution.
Any thoughts or ideas?
p.s: I'm working in c# so if it can be done with c#... it will be great :)
Thanks Asaf
When you insert a new user in the Database, their status should be "Deactivated" and you insert a "GUID" you generate alongside. You send them a link to your activation Page which would contain this GUID in the Query String. It will look like this:
www.YourSite.com/Activation.aspx?GUID=jdfhg43h98234
In the Activation.aspx page, you take this GUID from the Query String and compare it to the one you have in the Database. You then activate the Account having that GUID.
Create the user
Generate a unique string for the user
Have a Table that stores the unique string, the user Id ,a boolean that holds whether it got activated or not, the generation date, the expiration date and if you have different uses for these activation strings, the type(link to another table)
Now within the email you should get the string and write it within the email along with a link to the page you're going to use for validation such as whatever.com/verify.aspx?activationString=hd3fd33fen342n43
Within this page you do a query search within the table that holds the keys and if its not already validated
You have your users table in the DB (or where ever it is that you store your list of users), just add a column stating if the user's mail is validated.
To the validation mail add a link that fires some PHP with a user-specific code (like it's index in the DB). The PHP will set the user's "validated" column to true, and it'll be done.
It's not as complicated as it may seem at first.
The idea is to create a random key, save it to the database connected to the useraccount, supplying a link to the users e-mail which could point to a webservice(or regular website) which takes the key as a querystring which will then activate the account connected to that specific key.

Categories

Resources