Example #1
0
        // For creating a new profile from the scratch.
        public ActionResult CreateProfile()
        {
            Web.ViewModel.BusinessInformationViewModel bivm = new BusinessInformationViewModel();
            var username = HttpContext.User.Identity.Name;

            bivm.displayuser = _UserRepository.GetUserByUsername(username);


            return(View(bivm));
        }
Example #2
0
        public ActionResult BusinessInformation(int LeadId)
        {
            Web.ViewModel.BusinessInformationViewModel bivm = new BusinessInformationViewModel();
            bivm = _service.GetBusinessInformation(LeadId);
            User assignedUser = new User();

            if (bivm.lead.AssignedAAUserId != 0)
            {
                assignedUser = _UserRepository.GetUserById(bivm.lead.AssignedAAUserId);
            }
            else
            {
                assignedUser = _UserRepository.GetUserById(bivm.lead.AssignedSAUserId);
            }
            bivm.lead.AssignedUser = assignedUser;
            var username = HttpContext.User.Identity.Name;

            bivm.displayuser = _UserRepository.GetUserByUsername(username);
            //bivm.lead.AssignedUserRoleId = assignedUser.AssignedRoleId;

            return(View(bivm));
        }
Example #3
0
        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"));
            }
        }