public ActionResult sendLeadId(string values) { LeadIdforcal = int.Parse(values); Session["leadid"] = LeadIdforcal; var appts = _appointmentsRepository.GetAppointmentByLeadId(LeadIdforcal); var t = appts.Last(); string tempDayofApt = t.DayOfAppointment.ToString(); tempDayofApt = tempDayofApt.Remove(9); string starttemp = t.AppointmentDateFrom.ToString(); starttemp = starttemp.Remove(0, 9); starttemp = tempDayofApt + " " + starttemp; string endtemp = t.AppointmentDateTo.ToString(); endtemp = endtemp.Remove(0, 9); endtemp = tempDayofApt + " " + endtemp; DateTime tempstart = DateTime.Parse(starttemp); string z1 = tempstart.ToString("yyyy-MM-ddTHH':'mm':'ss"); DateTime tempend = DateTime.Parse(endtemp); string z2 = tempend.ToString("yyyy-MM-ddTHH':'mm':'ss"); Session["starttime"] = z1; Session["endtime"] = z2; return(View()); }
public ActionResult Suppress(int LeadId) { //Get Lead, Cards for Lead, Appointments for Lead, Accounts for Lead var leadSuppress = GetLeadByLeadId(LeadId); var cardsforlead = _CardRepository.GetCardByLeadId(LeadId); var appointmentsforlead = _AppointmentRepository.GetAppointmentByLeadId(LeadId); var accountsforlead = _AccountRepository.GetAccountsByLeadId(LeadId); //Delete all of them foreach (var card in cardsforlead) { _CardRepository.DeleteCard(card); } foreach (var appointment in appointmentsforlead) { _AppointmentRepository.DeleteAppointmentSheet(appointment); } foreach (var account in accountsforlead) { _AccountRepository.DeleteAccounts(account); } //leadSuppress.Suppressed = true; //We are deleting the lead here after deleting all the cards, accounts and appointmentsheets for him DeleteLead(leadSuppress); return(RedirectToAction("Index")); }
public ActionResult Suppress(string id) { Web.ViewModel.ImportLeadViewModel il = new Web.ViewModel.ImportLeadViewModel(); string[] ids = id.Split(','); // IList<Lead> leads; foreach (string leadid in ids) { int lid = int.Parse(leadid); var leadSuppress = GetLeadByLeadId(lid); var cardsforlead = _CardRepository.GetCardByLeadId(lid); var appointmentsforlead = _AppointmentRepository.GetAppointmentByLeadId(lid); var accountsforlead = _AccountRepository.GetAccountsByLeadId(lid); foreach (var card in cardsforlead) { _CardRepository.DeleteCard(card); } foreach (var appointment in appointmentsforlead) { _AppointmentRepository.DeleteAppointmentSheet(appointment); } foreach (var account in accountsforlead) { _AccountRepository.DeleteAccounts(account); } // leadSuppress.Suppressed = true; DeleteLead(leadSuppress); } return(Redirect("/LeadQueue/Index")); }
public ActionResult Create(Web.ViewModel.AccountInformationViewModel vm) { Report newRecord = new Report(); var newAccount = vm.account; vm.account.ParentLead = vm.leadId; vm.account.AssignedSalesRep = vm.assignedsa.UserId; vm.account.AACreator = vm.assignedaa.UserId; var appointmentforlead = _AppointmentRepository.GetAppointmentByLeadId(vm.leadId); foreach (var appointment in appointmentforlead) { if (appointment.Score == "Good") { newRecord = _ReportRepository.CheckExistingRecord(appointment.AssignedSalesAgent); newRecord.MonthlyAccounts++; var accountsforlead = _AccountRepository.GetAccountsByLeadId(vm.leadId); if (accountsforlead.Count() == 0) { newRecord.MonthlyCloses++; } _ReportRepository.SaveReports(newRecord); break; } } _AccountRepository.SaveAccounts(newAccount); //TO assign status to the lead for which account was created. Lead lead = new Lead(); lead = _LeadRepository.LeadByLeadID(vm.leadId); lead.Status = "Customer"; _LeadRepository.SaveLead(lead); //return RedirectToActionPermanent("Index"); return(Json(new { redirectToUrl = Url.Action("Index") })); }
public ActionResult CreateAppointment(Web.ViewModel.AppointmentSheetViewModel asvm) { try { #region record Report newRecord = new Report(); Report saveRecord = new Report(); User creator = new User(); var username = HttpContext.User.Identity.Name; creator = _UserRepository.GetUserByUsername(username); Web.ViewModel.BusinessInformationViewModel bivm = new BusinessInformationViewModel(); bivm = _service.GetBusinessInformation(asvm.appointmentSheet.ParentLeadId); int leadid = asvm.appointmentSheet.ParentLeadId; // get the previous appointsheet date and time values var appts = _appointmentsRepository.GetAppointmentByLeadId(leadid); var t = appts.Last(); string tempDayofApt1 = t.DayOfAppointment.ToString(); tempDayofApt1 = tempDayofApt1.Remove(9); string starttemp1 = t.AppointmentDateFrom.ToString(); starttemp1 = starttemp1.Remove(0, 9); starttemp1 = tempDayofApt1 + " " + starttemp1; string endtemp1 = t.AppointmentDateTo.ToString(); endtemp1 = endtemp1.Remove(0, 9); endtemp1 = tempDayofApt1 + " " + endtemp1; DateTime tempstart1 = DateTime.Parse(starttemp1); string z9 = tempstart1.ToString("yyyy-MM-ddTHH':'mm':'ss"); DateTime tempend1 = DateTime.Parse(endtemp1); string z10 = tempend1.ToString("yyyy-MM-ddTHH':'mm':'ss"); string EventReferencingId = asvm.appointmentSheet.Event_Reference; if (asvm.appointmentSheet.CreatorId == 0) { asvm.appointmentSheet.CreatorId = creator.UserId; asvm.appointmentSheet.CreatedAt = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // assigning userSales Agent to userid asvm.appointmentSheet.AssignedUser.UserId = asvm.appointmentSheet.AssignedSalesAgent; string tempid = asvm.appointmentSheet.ParentLeadId.ToString(); IEnumerable <AppointmentSheet> appointmentsCount = new List <AppointmentSheet>(); appointmentsCount = _AppointmentSheetRepository.GetAppointmentByLeadId(asvm.appointmentSheet.ParentLeadId); int tempcount = appointmentsCount.Count(); EventReferencingId = tempid + (tempcount).ToString(); } // To check if a SA is logged in to score the appointment asvm.appointmentSheet.LastUpdated = Convert.ToDateTime(DateTime.Now.ToShortDateString()); if (asvm.appointmentSheet.CreatorId != 0) { asvm.appointmentSheet.AssignedUser.UserId = asvm.appointmentSheet.AssignedSalesAgent; } asvm.appointmentSheet.Event_Reference = EventReferencingId; _service.SaveAppointmentSheet(asvm); #endregion #region createEventToo CalendarEventViewModel cevm = new CalendarEventViewModel(); CalendarEvent events = new CalendarEvent(); events = _EventsRepository.GetEventByAppointmentID(EventReferencingId); Lead tempLead = new Lead();// This lead is created so we can have the company name string tempDayofApt = asvm.appointmentSheet.DayOfAppointment.ToString(); tempDayofApt = tempDayofApt.Remove(9); string starttemp = asvm.appointmentSheet.AppointmentDateFrom.ToString(); starttemp = starttemp.Remove(0, 9); starttemp = tempDayofApt + " " + starttemp; string endtemp = asvm.appointmentSheet.AppointmentDateTo.ToString(); endtemp = endtemp.Remove(0, 9); endtemp = tempDayofApt + " " + endtemp; DateTime tempstart = DateTime.Parse(starttemp); //parse causing it to skip to catch, could be due to 12h time events.start = tempstart.ToString("yyyy-MM-ddTHH':'mm':'ss'.'fff'-'05':'00"); DateTime tempend = DateTime.Parse(endtemp); events.end = tempend.ToString("yyyy-MM-ddTHH':'mm':'ss'.'fff'-'05':'00"); // int tempLeadId = asvm.appointmentSheet.ParentLeadId; //tempLead = _service.GetLeadByLeadId(tempLeadId); events.title = tempLead.CompanyName; events.street = asvm.appointmentSheet.Street; events.city = asvm.appointmentSheet.City; events.state = asvm.appointmentSheet.State; events.zipcode = asvm.appointmentSheet.ZipCode; events.creator = asvm.appointmentSheet.CreatorId; events.Parent_Appointment_Id = asvm.appointmentSheet.AppointmentSheetId; events.Appointment_Reference = EventReferencingId; if (asvm.appointmentSheet.AssignedSalesAgent != 0) { events.Parent_User_Id = asvm.appointmentSheet.AssignedSalesAgent; } //This the event type set to "appointment" events.appointment = true; // The description by default empty so the SA can edit it at will later events.description = ""; events.zone = bivm.lead.ZoneNumber; cevm.calendarEvent = events; _EventsRepository.SaveCalendarEvent(cevm.calendarEvent); #endregion #region updateTimeslotToo var timeslots = _TimeSlotRepository.TimeSlots; // get the timeslots int lasttimeslotid = 0; int lastavailableSA = 0; Boolean update = false; // string z9 = (string)Session["starttime"]; // string z10 = (string)Session["endtime"]; //...//// Threshold threshold = new Threshold(); threshold = _ThresholdRepository.Thresholds.First(); string updateStartTime = events.start.Remove(19); string updateEndTime = events.end.Remove(19); if (string.Compare(updateStartTime, z9) != 0) // if the previous ts and current are not the same { foreach (var timeslot in timeslots) { if (string.Compare(timeslot.StartTime, z9) == 0) // find out the previous timeslot { lasttimeslotid = timeslot.TimeSlotId; lastavailableSA = timeslot.Num_Available_SA; update = true; // note down the timeslot id and available SA , set the updt flg } } } TimeSlot updateTimeSlot = new TimeSlot(); updateTimeSlot = _TimeSlotRepository.TimeSlots.SingleOrDefault(row => row.StartTime == updateStartTime); if (updateTimeSlot == null) { return(Content("Time slot is not available ,please refresh the page and reschedule the appointment")); } else { if (updateTimeSlot.Num_Available_SA != 0) { if (string.Compare(z9, updateTimeSlot.StartTime) == 0) // the same time is clicked again { updateTimeSlot.Num_Available_SA = updateTimeSlot.Num_Available_SA; } else // A different timedate is chosen for the appointment, the sa is reduced by 1 { updateTimeSlot.Num_Available_SA = updateTimeSlot.Num_Available_SA - 1; } updateTimeSlot.Title = updateTimeSlot.Num_Available_SA; } //Now update the color if (updateTimeSlot.Num_Available_SA > threshold.Upper_Calendar) { updateTimeSlot.Color = "green"; } if (updateTimeSlot.Num_Available_SA >= threshold.Lower_Calendar && updateTimeSlot.Num_Available_SA <= threshold.Upper_Calendar) { updateTimeSlot.Color = "yellow"; } if (updateTimeSlot.Num_Available_SA == 0) { updateTimeSlot.Color = "red"; } updateTimeSlot.All_Day = false; _TimeSlotRepository.SaveTimeSlot(updateTimeSlot); // If this is change in timedate for the appointment sheet , then , // change the available sa for the previous TS . if (update) { TimeSlot updateTimeSlotprev = new TimeSlot(); updateTimeSlotprev.TimeSlotId = lasttimeslotid; updateTimeSlotprev.Num_Available_SA = lastavailableSA + 1; updateTimeSlotprev.StartTime = z9; updateTimeSlotprev.EndTime = z10; updateTimeSlotprev.Title = updateTimeSlotprev.Num_Available_SA; updateTimeSlotprev.All_Day = false; if (updateTimeSlotprev.Num_Available_SA > threshold.Upper_Calendar) { updateTimeSlotprev.Color = "green"; } else if (updateTimeSlotprev.Num_Available_SA >= threshold.Lower_Calendar && updateTimeSlotprev.Num_Available_SA <= threshold.Upper_Calendar) { updateTimeSlotprev.Color = "yellow"; } else { updateTimeSlotprev.Color = "red"; } _TimeSlotRepository.SaveTimeSlot(updateTimeSlotprev); } } #endregion return(Content("Appointment in City " + asvm.appointmentSheet.City + " has been saved")); } catch { return(Content("This Lead was removed from the system. Please contact your Trinity Manager for details")); } }
public IEnumerable <Data.Domain.AppointmentSheet> GetAllAppointmentsForLead(int leadId) { var results = _AppointmentSheetRepository.GetAppointmentByLeadId(leadId); return(results); }