i am developing my app on google calendar integration. I got the error "Object Not initialized" when i am adding attendee to the EventAttendee object. Please review the code below...
Event Entry = new Event();
Entry.Summary = MeetingName;
Entry.Description = MeetingDetails;
EventDateTime dt_Start = new EventDateTime();
dt_Start.DateTime = meeting.StartTime.ToString("yyyy-MM-ddThh:mm:ss.000Z");
Entry.Start = dt_Start;
EventDateTime dt_End = new EventDateTime();
dt_End.DateTime = meeting.EndTime.ToString("yyyy-MM-ddThh:mm:ss.000Z");
Entry.End = dt_End;
if (invitees != null)
{
foreach (Participant invitee in invitees)
{
String str = invitee.Email;
str = invitee.Name;
Entry.Attendees.Add(new EventAttendee()
{
Email = invitee.Email,
DisplayName = WEB.HttpUtility.HtmlDecode(invitee.Name),
ResponseStatus = "accepted",
Organizer=false,
Resource=false
});
}
}
place where i am doing "Entry.Attendees.Add(new EventAttendee()" at this point i am getting the error...
I think you need to instantiate the list of EventAttendees first.
Try adding this after you create the entry-
Entry.Attendees = new List<EventAttendee>();
Then you could try this to add them-
var att = new EventAttendee()
{
DisplayName = "Bill Smith",
Email = "emailsmith#smith.test",
Organizer = false,
Resource = false,
};
Entry.Attendees.Add(att);
You should not be setting anything other than the email address for the attendee. The response status is for the attendee to set (why would you be able to accept a meeting for me that you created?) and the Organizer and Resource attributes are set by Google. It may be possible to set a DisplayName but it is not mandatory.
Related
Using web.ensureuser, may I know is there a way to still retrieve the SPUser object when the user does not exist in the AD anymore?
Or can I recreate the SPUser object?
foreach (var requestUser in requestUsers)
{
var item = requestUserList.Items.Add();
bool allowUnsafeUpdate = web.AllowUnsafeUpdates;
try
{
if (!allowUnsafeUpdate)
{
web.AllowUnsafeUpdates = true;
}
requestUser.User = web.EnsureUser(requestUser.LoginId); <---dead here
web.AllowUnsafeUpdates = allowUnsafeUpdate;
finally
{
web.AllowUnsafeUpdates = allowUnsafeUpdate;
}
var userProfile = UserProfile.GetUserProfile(requestUser.User);
item[OUASSharedMailboxRequestUserInternalName.RequestId] = requestIdLookup;
item[OUASSharedMailboxRequestUserInternalName.User] = requestUser.User;
item[OUASSharedMailboxRequestUserInternalName.PermissionType] = requestUser.PermissionType;
item[OUASSharedMailboxRequestUserInternalName.EmployeeId] = new SPFieldLookupValue(userProfile.ID, userProfile.EmployeeId);
item[OUASSharedMailboxRequestUserInternalName.LoginId] = requestUser.LoginId;
item[OUASSharedMailboxRequestUserInternalName.Action] = requestUser.Action;
item[OUASSharedMailboxRequestUserInternalName.Status] = requestUser.Status;
web.AllowUnsafeUpdates = true;
item.Update();
web.AllowUnsafeUpdates = false;
}
UPDATE: I was suggested to use the following:
requestUser.User = web.EnsureUser[requestUser.LoginId];
There are still some errors during the validations, and I'm currently resolving them.
Q: Are there any workarounds if the user does not exist in the AD as well as the SP List?
Use the following line of code to get the site user.
SPUser user = web.AllUsers.Cast<SPUser>().FirstOrDefault(u => u.LoginName.Contains("domain\\username"));
I created Intranet project which connect with AD to retrieve User's
data as Image , Department . I did my code and it works well but I had
the below error a lot of times .
string User = ConfigurationManager.AppSettings["User"];
string Password = ConfigurationManager.AppSettings["Password"];
var entry = new DirectoryEntry("LDAP://" + "xxxxx", User, Password);
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.SearchScope = SearchScope.Subtree;
string UserName = Page.User.Identity.Name;
searcher.Filter = string.Format(CultureInfo.InvariantCulture, "(sAMAccountName={0})", UserName.Split('\\')[1]);
SearchResult findUser = searcher.FindOne();
if (findUser != null)
{
DirectoryEntry user = findUser.GetDirectoryEntry();
//string loginuser = user.Properties["UserName"].Value.ToString();
LoggedUser = user.Properties["displayName"].Value.ToString();
Session.Add("LoggedUser", LoggedUser);
LoggedEmail = user.Properties["mail"].Value.ToString();
Session.Add("LoggedEmail", LoggedEmail);
string Mobile = user.Properties["Mobile"] != null && user.Properties["Mobile"].Value != null ? user.Properties["Mobile"].Value.ToString() : null;
string Login = user.Properties["sAMAccountName"].Value.ToString();
if (user.Properties["Department"].Value != null)
LoggedDepartement = user.Properties["Department"].Value.ToString();
_userDept = user.Properties["Department"].Value != null ? user.Properties["Department"].Value.ToString() : "";
ftier.AddLoggedUser(LoggedUser, LoggedDepartement, title, LoggedEmail, data, DateTime.Now, DateTime.Now, " nnnnn", true);
When I've done this in the past one of the problems was unusual characters in the properties of the user object caused this sort of error.
One approach would be to put error checking on each of the variables you're setting so the code can keep working, or export to a text file all the data and go through it using excel and look for unusual or strange control characters.
If the error always occurs at a certain person you could just look at the properties of that user and hope to find the issue that way.
Our issue was the use of Chinese simplified characters in some fields.
Hope this helps you track down your issue.
Dorje
Hi guys,
I'm learning to climb with EF ,I do have basic understanding of CRUD with EF ,but now I have a table which have a navigation property (Which I suspect is the bridge table) ,so I need to add value into the bridge table ,I think I can do it with navigational property.
Problem Explained:
Original partial DB Diagram
Partial EF Model Diagram
Code I Wrote:
protected void BtnAddUser_Click(object sender, EventArgs e)
{
DBEntities entities = new DBEntities();
var usr = new User();
//I thought I would add an Roles object into usr.UserRoles.Add(usrRoles);
//but UserRoles have only two fields ,RoleTypeId and UserId
//var usrRoles = new Roles()
//{Id=0,RoleDescription="dfdfdf",RoleType="WebSite Admin"};
usr.UserName = TxtbxUserName.Text;
usr.Password = TxtBxPassword.Text;
usr.Email = TxtbxEmail.Text;
usr.CreateDate = DateTime.Now;
usr.LastActivityDate = DateTime.Now;
usr.IsEnabled = true;
//What to Add in the .Add method
usr.UserRoles.Add(
entities.User.AddObject(usr);
int result = entities.SaveChanges();
LblMsg.Text = result == 1 ? "User created successfully." : "An error occured ,please try later.";
entities.Dispose();
}
Update (What I have tried so far):
I fetch "Website Admin" role from roles table and put it into ObjectContext.UserRoles.Add(UserRoleWebsiteAdmin);
So that what I did in the code,
//Fetch WebsiteAdmin from Roles
var userRole = from usrRole in entities.Roles
where usrRole.Id == 1
select usrRole;
usr.UserName = TxtbxUserName.Text;
//same old code of usr.Property = someTextBox
//I have tried to type cast it LinqtoEntities result into Roles
usr.UserRoles.Add((Roles)userRole);
Exception generated
P.S: Let me know if you need more clarification.
Maybe you can use using http://msdn.microsoft.com/en-us/library/yh598w02.aspx and object initializer http://msdn.microsoft.com/en-us/library/bb384062.aspx for better readability so:
using(DBEntities entities = new DBEntities())
{
//Make user object
var user = new User{
UserName = TxtbxUserName.Text,
Password = TxtBxPassword.Text,
Email = TxtbxEmail.Text,
CreateDate = DateTime.Now,
LastActivityDate = DateTime.Now,
IsEnabled = true
};
//Fetch type of Role from Roles table
var userRole = entities.Roles.Where(x=>x.usrRole.Id ==1).Single();
user.UserRoles.Add(userRole);
entities.User.AddObject(user);
int result = entities.SaveChanges();
LblMsg.Text = result == 2 ? "User created succesfully." : "An error occured ,please try later.";
}
Regards
Well thanks guys...
Here what I have done and it works,
DBEntities entities = new DBEntities();
//Make user object
var usr = new User();
//Fetch type of Role from Roles table
var userRole = (from usrRole in entities.Roles
where usrRole.Id == 1
select usrRole).Single();
//copy user related info from textboxes
usr.UserName = TxtbxUserName.Text;
usr.Password = TxtBxPassword.Text;
usr.Email = TxtbxEmail.Text;
usr.CreateDate = DateTime.Now;
usr.LastActivityDate = DateTime.Now;
usr.IsEnabled = true;
usr.UserRoles.Add(userRole as Roles);
entities.User.AddObject(usr);
int result = entities.SaveChanges();
LblMsg.Text = result == 2 ? "User created succesfully." : "An error occured ,please try later.";
entities.Dispose();
I'm trying to create a Facebook Mobile Application using asp.net and MVC3 and integrate Facebook Credits as a payment method. First of all, taking the recent annoucements into consideration, is it now possible to have a mobile web application that accepts Facebook Credits?
If so, I've taken the example provided in the following post
http://www.m-webs.com/blog_facebookcredits.html
And implemented the following Controller action:
public JsonResult CallBack()
{
string fborder_info = Request.Form["order_info"];
string fborder_id = Request.Form["order_id"];
string fbmethod = Request.Form["method"];
if (fbmethod == "payments_get_items")
{
fborder_info = fborder_info.Substring(1, (fborder_info.Length - 2)); // remove the quotes
ulong credscost = 2; // Price of purchase in facebook credits
var theItem = new FacebookBuyItem()
{
item_id = 123456789,
description = "Own yours today!",
price = credscost,
title = "Digital Unicorn",
product_url = "http://www.facebook.com/images/gifts/21.png",
image_url = "http://www.facebook.com/images/gifts/21.png"
};
var res = new Dictionary<string, object>();
res["method"] = fbmethod;
res["order_id"] = fborder_id;
res["content"] = new object[] { theItem };
var jss = new JavaScriptSerializer();
var ob = jss.Serialize(res);
ob = ob.Replace("#$", #"\/".Replace("//", #"\/"));
return Json(ob, JsonRequestBehavior.AllowGet);
}
return null;
}
I've verified that the callback is being requested by facebook, and I've also captured the response being sent back, which appears to contain all of the required information to display the purchase dialog, but I'm still getting the following error message:
API Error Code: 1151
API Error Description: Sorry, but this app may not be eligible to accept Facebook Credits. If this app has accepted credits before, please try again.
Error Message: Invalid Application
and when tested from a mobile browser:
Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again.
I've also noticed that my callback is being requested twice which doesn't seem right either.
Any insight into how to get my integration up and running would be greatly appreciated. My Facebook AppId is 177876855621874
Thanks.
Update: So I played around with the examples given and reverted back to webforms in order to test the example given at http://www.m-webs.com/blog_facebookcredits.html. In order to get this solution working in an asp.net MVC3 application I had to change the action type to HttpResponse instead of JsonResult which makes sense as the JsonResult leaves elements out that would normally be included in a HttpResponse.
So the Controller Action ended up looking like this:
[HttpPost]
public HttpResponse CallBack()
{
if (Request.Form["signed_request"] != null)
{
var decodeFbSignedRequest = FacebookSignedRequest.Parse(FacebookApplication.Current.AppSecret,
Request.Form["signed_request"]);
LogHelper.MicroLogMsg("SIGNED REQUEST DECODE:: " + decodeFbSignedRequest.Data);
}
string fborder_id = Request.Form["order_id"];
string fbmethod = Request.Form["method"];
string fborder_info = Request.Form["order_info"]; // Use this to look up a product on the database..
if (fbmethod == "payments_get_items")
{
int credscost = 2; // Price of purchase in facebook credits
var theItem = new FacebookBuyItem()
{
item_id = "123456AA",
description = "[Test Mode] Own yours today!",
price = credscost,
title = "[Test Mode] Digital Unicorn",
product_url = #"http:\/\/www.facebook.com\/images\/gifts\/21.png",
image_url = #"http:\/\/www.facebook.com\/images\/gifts\/21.png"
};
// Return the initial response to FB
//------------------------------------------
var res = new Dictionary<string, object>();
res["method"] = fbmethod;
res["content"] = new object[] { theItem };
var jss = new JavaScriptSerializer();
string ob = jss.Serialize(res);
LogHelper.MicroLogMsg(ob);
Response.ContentType = "application/json";
Response.Write(ob);
Response.End();
}
return null;
}
I hope this helps out anyone doing an MVC3 implementation for Facebook Credits.
i made an application that allow me to open conversation between friends, when someone send me a message i got a notification "John send you a new message" and when another person in the conversation send me a message a new notification is made ,,, my problem is that i don't want to make a new notification but i want to update the old notification to be for ex. like this " John and Alfred send you a new message"..
var user = users.Where(x => x != CurrentUserId);
foreach (var item in user)
{
var check = entities.Notifications.SingleOrDefault(i => (i.NotificationForId == id
&& i.NotificationForType == IdType && i.UserId == item));
if (check == null)
{
Notification notify = new Notification()
{
NotificationForId = id,
NotificationForType = IdType,
DateTime = DateTime.Now,
Message = GenerateMessage(),
UserId = item,
SenderID = CurrentUserId.ToString(),
SenderName = CurrentUserName
};
entities.Notifications.AddObject(notify);
}
else
{
check.Checked = false;
check.DateTime = DateTime.Now;
}
here it check if there are any notification for a user , if null then make a new notification else " Update the notification "
Your else block indicates the notification exists on the database, you can update the properties there. To save the changes made, both for insert and update call the method entities.SaveChanges()