Exemplo n.º 1
0
		protected void Save()
		{
			//del string cc = txtCc.Text;
			//del string ccLeads = txtCcLead.Text;
			//del string bcc = txtBcc.Text;
			//del string bccLeads = txtBccLead.Text;
			if (hfActivityName.Value.Equals("Email"))
			{
				if (lvEmailLeads.Items.Count == 0 && lvEmailBccLeads.Items.Count == 0)
				{
					lblEmailLeadsMessage.CssClass = "lblLeadsListMessageVisible";
					LeadEmail.Attributes["style"] = "border-color:red";
					BccEmail.Attributes["style"] = "border-color:red";
					return;
				}
			}
			else if (hfActivityName.Value.Equals("Letter") || hfActivityName.Value.Equals("Phone Call"))
			{
				if (lvLeadsToActivity.Items.Count == 0)
				{
					lblLeadsListMessage.CssClass = "lblLeadsListMessageVisible";
					divLeadsToActivity.Attributes["style"] = "border-color:red";
					return;
				}
			}
			int id = GetActivitiesID();
			int typeID = GetTypeID();
			List<Recipient> users = new List<Recipient>();
			List<Recipient> leads = new List<Recipient>();
			Activity activity = new Activity();
			if (id > 0)
			{
				activity.ActivityID = id;
				var actTypeID = DataManager.GetTypeActivityIDByActivityID(id);
				activity.ActivityType = new ActivityType { TypeID = actTypeID, Type = DataManager.GetActivityTypeByActivityID(id) };
			}
			if (typeID > 0)
			{
				activity.ActivityType = DataManager.GetActivityTypes().First(at => at.TypeID == typeID);
			}
			if (id < 0 && typeID < 0)
			{
				//throw new ApplicationException("!!!!!!!!!!!!!!!!!!");
				Response.Redirect(PageConstants.ErrorPage);
			}

			List<Recipient> listCc = null;
			List<Recipient> listBcc = null;

			List<Recipient> listCcLeads = null;
			List<Recipient> listBccLeads = null;


			//del if (cc != string.Empty)
			//del {
			//del 	listCc = ParseRecipientUsersStrings(cc, false);
			//users.AddRange(ParseRecipientUsersStrings(cc, false));
			//del }

			//del if (bcc != string.Empty)
			//del {
			//del 	listBcc = ParseRecipientUsersStrings(bcc, false);
			//users.AddRange(ParseRecipientUsersStrings(bcc, true));
			//del }

			//del if (ccLeads != string.Empty)
			//del {
			//del 	listCcLeads = ParseRecipientLeadsStrings(ccLeads, false);
			//leads.AddRange(ParseRecipientLeadsStrings(ccLeads, false));
			//del }
			//del if (bccLeads != string.Empty)
			//del {
			//del 	listBccLeads = ParseRecipientLeadsStrings(bccLeads, true);
			//leads.AddRange(ParseRecipientLeadsStrings(bccLeads, true));
			//del }
			if (txtDue.Value != string.Empty)
			{
				DateTime dueDate;
				try
				{
					StringBuilder dateTime = new StringBuilder();
					dateTime.Append(txtDue.Value);
					if (txtTime.Text != string.Empty)
					{
						dateTime.Append(" ");
						dateTime.Append(txtTime.Text);
						dateTime.Append(ddlTime.SelectedValue);
					}
					dueDate = DateTime.Parse(dateTime.ToString());
					activity.Due = dueDate;
				}
				catch (FormatException)
				{
					Console.WriteLine("Date is not in the correct format.");
				}
			}

			if ((listCc != null) && (listBcc != null))
			{
				foreach (var litem in listCc)
				{
					if (listBcc.Select(l => l.FullName).Contains(litem.FullName))
					{
						//del lblMessage.Visible = true;
						//del lblMessage.Text = _message;
						return;
					}
				}
				users.AddRange(listBcc);
				users.AddRange(listCc);
			}
			else
			{
				if (listCc != null)
					users.AddRange(listCc);
				if (listBcc != null)
					users.AddRange(listBcc);
			}

			//

			if ((listBccLeads != null) && (listCcLeads != null))
			{
				foreach (var litem in listCcLeads)
				{
					if (listBccLeads.Select(l => l.FullName).Contains(litem.FullName))
					{
						//del lblMessage.Visible = true;
						//del lblMessage.Text = _message;
						return;
					}
				}
				users.AddRange(listBccLeads);
				users.AddRange(listCcLeads);
			}
			else
			{
				if (listCcLeads != null)
					users.AddRange(listCcLeads);
				if (listBccLeads != null)
					users.AddRange(listBccLeads);
			}
			activity.Sender = DataManager.GetUsersInfo().Where(u => u.FullName == txtSender.Text).First();
			//activity.Sender = new UserInformation {}
			activity.Sender = new UserInformation { Login = Membership.GetUser().UserName };
			activity.Recipient = new List<Lead>();
			int bccBegin = 0;
			switch (activity.ActivityType.Type.ToLower())
			{
				case "phone call":
					activity.Post = txtSubjectNote.Text;
					foreach (var item in lvLeadsToActivity.Items)
					{
						var controls = item.Controls;
						foreach (var control in item.Controls)
						{
							var lblPhoneLeadID = control as Label;
							if (lblPhoneLeadID != null)
							{
								if (lblPhoneLeadID.CssClass.Equals("lblLeadID"))
								{
									activity.Recipient.Add(DataManager.GetLeadById(int.Parse(lblPhoneLeadID.Text)));
									break;
								}
							}
						}
					}
					break;
				case "email":
					activity.Post = hfText.Value;
					foreach (var item in lvEmailLeads.Items)
					{
						var controls = item.Controls;
						foreach (var control in item.Controls)
						{
							var emailLeadID = control as Label;
							if (emailLeadID != null)
							{
								if (emailLeadID.CssClass.Equals("lblLeadID"))
								{
									activity.Recipient.Add(DataManager.GetLeadById(int.Parse(emailLeadID.Text)));
									break;
								}
							}
						}
					}

					bccBegin = activity.Recipient.Count();


					foreach (var item in lvEmailBccLeads.Items)
					{
						var controls = item.Controls;
						foreach (var control in item.Controls)
						{
							var emailBccLeadID = control as Label;
							if (emailBccLeadID != null)
							{
								if (emailBccLeadID.CssClass.Equals("lblLeadID"))
								{
									activity.Recipient.Add(DataManager.GetLeadById(int.Parse(emailBccLeadID.Text)));
									break;
								}
							}
						}
					}
					break;
				case "letter":
					var contr = lvLeadsToActivity.Controls;
					activity.Post = txtSubjectNote.Text;
					foreach (var item in lvLeadsToActivity.Items)
					{
						foreach (var control in item.Controls)
						{
							var lblLetterLeadID = control as Label;
							if (lblLetterLeadID != null)
							{
								if (lblLetterLeadID.CssClass.Equals("lblLeadID"))
								{
									activity.Recipient.Add(DataManager.GetLeadById(int.Parse(lblLetterLeadID.Text)));
									break;
								}
							}
						}
					}
					break;
			}
			activity.CreatedBy = new UserInformation { Login = Membership.GetUser().UserName };
			activity.Subject = txtSubject.Text;
			//activity.Post = txtSubjectNote.Text;
			activity.Owner = new UserInformation { Login = ddlOwner.SelectedValue };
			activity.Priority = new Priority { PriorityID = int.Parse(ddlPriority.SelectedValue) };
			activity.CreatedOn = DateTime.Now;
			activity.Status = new ActivityStatus { StatusID = int.Parse(ddlStatus.SelectedValue) };


			foreach (var l in activity.Recipient)
			{
				DataManager.LeadModified(l.LeadID.Value);
			}
			//Sending Notification Start           
			MembershipUser userNew = Membership.GetUser(ddlOwner.SelectedValue);
			Guid newOwner = (Guid)userNew.ProviderUserKey;
			var path = VirtualPathUtility.ToAbsolute("~/");
            bool isSend = false;
			if (activity.ActivityID.HasValue)
			{
				var loginOldOwner = DataManager.GetActivityById(activity.ActivityID.Value).Owner.Login;
				var userOld = Membership.GetUser(loginOldOwner);
				var oldOwner = (Guid)userOld.ProviderUserKey;
                if (oldOwner != newOwner)
                {
                    NotificationManager.ActivityNotify(newOwner, oldOwner, activity.ActivityID.Value, path);                   
                }
                isSend = true;
			}
			//Sending Notification End

			try
			{
				int actID;
				if (activity.ActivityType.Type.ToLower().Equals("email"))
				{
					actID = DataManager.SaveEmailActivity(activity, bccBegin);
				}
				else
				{
					actID = DataManager.SaveActivity(activity);
				}
				SaveNote(actID);
				if (actID > 0)
				{
					DataManager.SaveRecipients(users, leads, actID);
                    if (!isSend)
                    {
                        NotificationManager.ActivityNotify(newOwner, null, actID, path);
                    }
				}
				else
				{
					DataManager.SaveRecipients(users, leads, id);
				}

			}
			catch (ApplicationException)
			{
				Response.Redirect(PageConstants.ErrorPage);
			}
			Response.Redirect(PageConstants.ActivitiesPage);
			Session.Remove("addedLeads");
			Session.Remove(_retURL);
		}
Exemplo n.º 2
0
		public static int SaveEmailActivity(Activity entity, int Bcc)
		{
			return _dataActivityProvider.SaveEmailActivity(entity, Bcc);
		}
Exemplo n.º 3
0
		public int SaveEmailActivity(Activity entity, int Bcc)
		{
			using (var dc = new EngageCCTDataClassesDataContext())
			{
				T_Activity tActivity;
				if (!entity.ActivityID.HasValue)
				{
					tActivity = new T_Activity();
					dc.T_Activities.InsertOnSubmit(tActivity);
				}
				else
				{
					tActivity = dc.T_Activities.SingleOrDefault(a => a.ActivityID == entity.ActivityID);
					if (tActivity == null)
					{
						throw new ApplicationException("Activity not found");
					}
				}
				tActivity.actCreationDate = entity.CreatedOn;
				tActivity.actPost = entity.Post;
				tActivity.actSubject = entity.Subject;
				tActivity.Author = entity.CreatedBy.Login;
				tActivity.Owner = entity.Owner.Login;
				tActivity.PriorityID = entity.Priority.PriorityID;
				tActivity.RecipientID = (int)entity.Recipient.First().LeadID;
				tActivity.Sender = entity.Sender.Login;
				tActivity.TypeID = entity.ActivityType.TypeID;
				tActivity.StatusID = entity.Status.StatusID;

				if (entity.Due != null)
				{
					tActivity.actDue = entity.Due;
				}
				if (entity.Phone != null)
				{
					tActivity.actPhone = entity.Phone;
				}
				if (entity.Address != null)
				{
					tActivity.actAddress = entity.Address;
				}
				if (entity.Notes != null)
				{
					foreach (Note item in entity.Notes)
					{
						if (!item.NoteID.HasValue)
						{
							item.NoteID = SaveNote(item, tActivity.ActivityID);
						}
						else
						{
							T_Note tNote = dc.T_Notes.Single(n => n.NoteID == item.NoteID);
							if (tNote.ntEdited < item.Edited)
							{
								SaveNote(item, tActivity.ActivityID);
							}
						}
					}
				}

				dc.SubmitChanges();
				this.SaveEmailActivityLead(tActivity.ActivityID, entity.Recipient, Bcc);
				return tActivity.ActivityID;
			}
		}
Exemplo n.º 4
0
		public static int SaveActivity(Activity entity)
		{
			return _dataActivityProvider.SaveActivity(entity);
		}
Exemplo n.º 5
0
		private static Activity GetActivityEntity(T_Activity tActivity)
		{
			using (var dc = new EngageCCTDataClassesDataContext())
			{
				UserInformation createdBy = new UserInformation { FirstName = tActivity.T_UserInformation.usrFirstName, LastName = tActivity.T_UserInformation.usrLastName, Login = tActivity.T_UserInformation.Login };
				UserInformation owner = new UserInformation { FirstName = tActivity.T_UserInformation1.usrFirstName, LastName = tActivity.T_UserInformation1.usrLastName, Login = tActivity.T_UserInformation1.Login };
				UserInformation sender = new UserInformation { FirstName = tActivity.T_UserInformation2.usrFirstName, LastName = tActivity.T_UserInformation2.usrLastName, Login = tActivity.T_UserInformation2.Login };

				var tActivityLeads = dc.T_ActivityLeads.Where(al => al.ActivityID == tActivity.ActivityID);
				var tLeads = dc.T_Leads.Where(l => tActivityLeads.Any(ac => ac.LeadID == l.LeadID));
				CCTLeadProvider leadProvider = new CCTLeadProvider();
				List<Lead> recipients = new List<Lead>();
				foreach (var lead in tLeads)
				{
					var recipient = leadProvider.GetLeadEntity(lead);
					recipients.Add(recipient);
				}

				Priority priority = new Priority { PriorityID = tActivity.T_Priority.PriorityID, Type = tActivity.T_Priority.prType };
				ActivityType activityType = new ActivityType { Type = tActivity.T_ActivityType.atType, TypeID = tActivity.T_ActivityType.TypeID };

				DateTime createdDate = tActivity.actCreationDate;
				DateTime? dueDate = tActivity.actDue;

				List<Note> notes = new List<Note>();
				var tActivityNotes = dc.T_ActivityNotes.Where(e => e.ActivityID == tActivity.ActivityID);
				foreach (var tActivityNote in tActivityNotes)
				{
					notes.Add(leadProvider.GetNoteEntity(tActivityNote.T_Note));
				}


				//Activity activity = new Activity()
				//{
				//  ActivityID = tActivity.ActivityID,
				//  CreatedBy = createdBy,
				//  ActivityType = activityType,
				//  CreatedOn = createdDate,
				//  Due = dueDate,
				//  Notes = notes,
				//  Owner = owner,
				//  Post = tActivity.actPost,
				//  Priority = priority,
				//  Recipient = recipient,
				//  Sender = sender,
				//  Subject = tActivity.actSubject
				//};

				ActivityStatus status = new ActivityStatus();
				status.StatusID = tActivity.StatusID;
				var stat = dc.T_ActivityStatus.Where(st => st.StatusID == status.StatusID).Select(s => s.asStatus).First();
				status.Status = stat;
				Activity activity = new Activity();
				activity.ActivityID = tActivity.ActivityID;
				activity.CreatedBy = createdBy;
				activity.ActivityType = activityType;
				activity.CreatedOn = createdDate;
				activity.Due = dueDate;
				activity.Notes = notes;
				activity.Owner = owner;
				activity.Post = tActivity.actPost;
				activity.Priority = priority;
				activity.Recipient = recipients;
				activity.Sender = sender;
				activity.Subject = tActivity.actSubject;
				activity.Status = status;

				if (tActivity.actPhone != null)
				{
					activity.Phone = tActivity.actPhone;
				}
				if (tActivity.actAddress != null)
				{
					activity.Address = tActivity.actAddress;
				}

				return activity;
			}
		}