示例#1
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);
        }
示例#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 ActionResult Create(Web.ViewModel.UserCreateViewModel uc, string values)
        {
            // In addition to updating the User table , also update the timeslot table if
            // the assigned roleid is 3 (for SA) . If the assigned roleid is 3 , then the number
            // of available SA's should go up by one for all the timeslots .
            // You may right it in a static method and call the update code , so that if a user is
            // deleted , then the number of available SA's go down by 1 .
            int       a;
            var       newUser      = uc.user;
            PhoneUser newPhoneUser = new PhoneUser();

            IEnumerable <User> users = new List <User>();

            users = _UserRepository.GetAllUsersByRole(3);
            a     = users.Count();



            if (newUser.selectedRole == "Administrator")
            {
                newUser.AssignedRoleId = 1;
            }
            if (newUser.selectedRole == "Manager")
            {
                newUser.AssignedRoleId = 2;
            }
            if (newUser.selectedRole == "SA")
            {
                newUser.AssignedRoleId = 3;
            }
            if (newUser.selectedRole == "AA")
            {
                newUser.AssignedRoleId = 4;
            }
            if (newUser.selectedRole == "Customer Service Agent")
            {
                newUser.AssignedRoleId = 5;
            }

            var temp = _UserRepository.GetUserByUsername(newUser.UserName);

            if (temp != null)
            {
                return(Json(new { msg = "Not Null. User exists." }));
            }

            newUser.Address2    = "";
            newUser.newPassword = "******";                 // Default first time password
            newUser.IsActive    = true;
            _UserRepository.SaveUser(newUser);

            if (newUser.AssignedRoleId == 3)
            {
                // add one available SA in the timeslot table .
                var timeslots = _timeSlotRepository.TimeSlots;    // get the timeslots

                Threshold threshold = new Threshold();
                threshold = _ThresholdRepository.Thresholds.First();

                foreach (var timeslot in timeslots)
                {
                    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";
                    }
                    else if (timeslot.Num_Available_SA >= threshold.Lower_Calendar && timeslot.Num_Available_SA <= threshold.Upper_Calendar)
                    {
                        timeslot.Color = "yellow";
                    }
                    else
                    {
                        timeslot.Color = "red";
                    }

                    _timeSlotRepository.SaveTimeSlot(timeslot);
                }
            }

            var tempUser = _UserRepository.GetUserByUsername(uc.user.UserName);

            newPhoneUser.CRMUserId  = tempUser.UserId;
            newPhoneUser.Email      = uc.user.EmailOne;
            newPhoneUser.Extension  = uc.extensionNum;
            newPhoneUser.FirstName  = uc.user.FirstName;
            newPhoneUser.MiddleName = uc.user.MiddleName;
            newPhoneUser.LastName   = uc.user.LastName;
            newPhoneUser.AccountId  = 1155;

            _PhoneUserRepos.SavePhoneUser(newPhoneUser);

            if (values != "")
            {
                var ids = values.Split(',');

                UserZone uz = new UserZone();

                var usernew = _UserRepository.GetUserByUsername(uc.user.UserName);

                uz.UserID = usernew.UserId;

                for (int i = 0; i < ids.Length; i++)
                {
                    uz.ZoneId = Convert.ToInt32(ids[i]);
                    _UserZoneRepository.SaveUserZone(uz);
                }
            }
            return(Json(new { redirectToUrl = Url.Action("Index") }));
        }