public ActionResult AssignAppointment(string text, string id)
        {
            string[] ids   = id.Split(',');
            string[] names = text.Split(',');

            AppointmentSheet appointment;

            User user = _UsageRepository.GetUserIDByName(names[0], names[1]);

            foreach (string appointmentid in ids)
            {
                int aid = int.Parse(appointmentid);

                appointment = _AppointmentRepos.GetAppointmentByAppointmentId(aid);
                Lead lead = _LeadRepos.LeadByLeadID(appointment.ParentLeadId);
                _UsageRepository.SaveAssignedSALeads(lead, user.UserId);

                _UsageRepository.SaveAssignedAppointments(appointment, user.UserId);

                // need ref id to appoint parent_user_integer

                string EventReferencingId = appointment.Event_Reference;
                Web.ViewModel.CalendarEventViewModel cevm = new Web.ViewModel.CalendarEventViewModel();
                CalendarEvent events = new CalendarEvent();
                events = _EventsRepository.GetEventByAppointmentID(EventReferencingId);
                events.Parent_Appointment_Id = appointment.AppointmentSheetId;
                events.Parent_User_Id        = user.UserId;
                events.appointment           = true;
                events.street      = appointment.Street;
                events.city        = appointment.City;
                events.state       = appointment.State;
                events.zipcode     = appointment.ZipCode;
                events.description = "";
                events.creator     = appointment.CreatorId;
                events.assigned    = appointment.AssignedSalesAgent;
                cevm.calendarEvent = events;
                _EventsRepository.SaveCalendarEvent(cevm.calendarEvent);
            }


            //return RedirectToAction("Index", "ImportLead");
            return(Redirect("/AppointmentQueue/Index"));
        }
Пример #2
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"));
            }
        }
Пример #3
0
        public JsonResult CreateCalendar(FormCollection newCalendarEvent)
        {
            CalendarEventViewModel cevm   = new CalendarEventViewModel();
            CalendarEvent          events = new CalendarEvent();
            string starttemp = newCalendarEvent[0].Remove(0, 4);

            starttemp = starttemp.Remove(20);
            string endtemp = newCalendarEvent[1].Remove(0, 4);

            endtemp = endtemp.Remove(20);
            DateTime tempstart = DateTime.Parse(starttemp);

            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");
            events.title       = newCalendarEvent[3].ToString();
            events.street      = newCalendarEvent[4].ToString();
            events.city        = newCalendarEvent[5].ToString();
            events.state       = newCalendarEvent[6].ToString();
            events.description = newCalendarEvent[9].ToString();

            if (newCalendarEvent[7] == "")
            {
                events.zipcode = 12345;
            }
            else
            {
                events.zipcode = int.Parse(newCalendarEvent[7].ToString());
            }
            //This guy will not take really big integers

            // code to store SA agent calender . Maya AA
            var username = HttpContext.User.Identity.Name;
            var user     = _UserRepository.GetUserByUsername(username);

            events.Parent_User_Id = user.UserId;

            //..............//

            cevm.calendarEvent = events;
            _eventsRepository.SaveCalendarEvent(cevm.calendarEvent);

            // you have to save the calendar events in the timeslot repository as well
            // so that it shows up in the AA table .

            string z1;

            Threshold threshold = new Threshold();

            threshold = _ThresholdRepository.Thresholds.First();

            var taskList = new List <CalendarDTO>();
            IEnumerable <TimeSlot> timeslots = new List <TimeSlot>();

            timeslots = _timeSlotRepository.TimeSlots;

            z1 = events.start;
            z1 = z1.Remove(19);
            foreach (var timeslot in timeslots)
            {
                if (string.Compare(z1, timeslot.StartTime) == 0)
                {
                    timeslot.Num_Available_SA = timeslot.Num_Available_SA - 1;
                    timeslot.Title            = timeslot.Num_Available_SA;

                    if (timeslot.Num_Available_SA > threshold.Upper_Calendar)
                    {
                        timeslot.Color = "green";
                    }
                    if (timeslot.Num_Available_SA >= threshold.Lower_Calendar && timeslot.Num_Available_SA <= threshold.Upper_Calendar)
                    {
                        timeslot.Color = "yellow";
                    }
                    if (timeslot.Num_Available_SA == 0)
                    {
                        timeslot.Color = "red";
                    }
                    _timeSlotRepository.SaveTimeSlot(timeslot);
                }
            }

            return(null);
        }