Пример #1
0
        /// <summary>
        /// Create and return the TimeSlot object from passed tbl_TimeSlot
        /// </summary>
        /// <param name="tSlot"></param>
        /// <returns></returns>
        private TimeSlot GetTimeSlotDetails(tbl_TimeSlot tSlot)
        {
            var context = new dbDataContext();
            var timeSlot = new TimeSlot
            {
                TimeSlotId = tSlot.TimeSlotId,
                InterviewId = tSlot.InterviewId,
                SlotDate = Convert.ToDateTime(tSlot.InterviewDate).ToShortDateString(),
                SlotTime = Convert.ToDateTime(tSlot.InterviewDate).ToString("HH:mm"),
                Duration = tSlot.Duration,
                CreatedDate = tSlot.CreatedDate,
                LastUpdatedDate = Convert.ToDateTime(tSlot.LastUpdatedDate)
            };

            if (tSlot.LocationId > 0)
                timeSlot.Location = GetInterviewLocation(tSlot.LocationId);

            //contact
            timeSlot.AllocatedContact = null;
            if (tSlot.InterviewRequestId > 0)
            {
                // get the request detail
                var request = context.tbl_InterviewRequests.FirstOrDefault(t => t.InterviewRequestId == tSlot.InterviewRequestId);
                if (request != null)
                {
                    // get the contact
                    var contact = context.tbl_Candidates.FirstOrDefault(t => t.CandidateId == request.CandidateId);
                    if (contact != null)
                    {
                        timeSlot.AllocatedContact = new TimeSlotContact
                        {
                            ContactId = contact.CandidateId,
                            FullName = contact.Forename + " " + contact.Surname
                        };
                    }
                }
            }

            //interviewers
            var interviewers = new List<Interviewer>();
            var qInterviewers = (context.tbl_TimeSlotInterviewers.Where(x => x.TimeSlotId == tSlot.TimeSlotId));

            foreach (var i in qInterviewers)
            {
                if (i.IsUser)
                {
                    //this is a user
                    interviewers.Add((context.tbl_Users.Where(x => x.UserId == i.InterviewerId).Select(x => new Interviewer
                    {
                        Forename = x.Forename,
                        Surname = x.Surname,
                        Email = x.Email,
                        Id = x.UserId,
                        IsUser = true
                    }).FirstOrDefault()));
                }
                else
                {
                    //get from interviewer table
                    interviewers.Add((context.tbl_Interviewers.Where(x => x.InterviewerId == i.InterviewerId).Select(x => new Interviewer()
                    {
                        Forename = x.Forename,
                        Surname = x.Surname,
                        Email = x.Email,
                        Id = x.InterviewerId,
                        IsUser = false

                    }).FirstOrDefault()));
                }
            }
            timeSlot.Interviewers = interviewers;
            return timeSlot;
        }
Пример #2
0
        /// <summary>
        /// This function adds update time slot
        /// </summary>
        /// <param name="tSlot"></param>
        /// <returns></returns>
        public int AddTimeSlot(TimeSlot tSlot)
        {
            var context = new dbDataContext();
            var timeSlot = context.tbl_TimeSlots.FirstOrDefault(t => t.TimeSlotId == tSlot.TimeSlotId) ??
                        new tbl_TimeSlot();
            //set interview date
            var intDate = Convert.ToDateTime(tSlot.SlotDate);
            var hour = int.Parse(tSlot.SlotTime.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            var min = int.Parse(tSlot.SlotTime.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1]);
            intDate = new DateTime(intDate.Year, intDate.Month, intDate.Day, hour, min, 0);
            timeSlot.InterviewId = tSlot.InterviewId;
            timeSlot.InterviewDate = intDate;
            timeSlot.Duration = tSlot.Duration;
            timeSlot.LocationId = tSlot.Location != null ? tSlot.Location.Id : 0;
            timeSlot.LastUpdatedDate = DateTime.Now;
            if (timeSlot.TimeSlotId <= 0)
            {
                timeSlot.CreatedDate = DateTime.Now;
                context.tbl_TimeSlots.InsertOnSubmit(timeSlot);
            }
            context.SubmitChanges();
            var slotId = timeSlot.TimeSlotId;

            if (slotId > 0)
            {
                var interviewers = tSlot.Interviewers != null ? tSlot.Interviewers.ToList() : new List<Interviewer>();
                AddInterviwersToInteriew(slotId, interviewers, tSlot.LastUpdatedBy);
                // add a history record for interview update
                new Histories().AddHistory(new History
                {
                    RefId = tSlot.InterviewId,
                    RefType = "Interview",
                    ClientUserId = tSlot.LastUpdatedBy,
                    TypeId = 21,
                    SubRefType = tSlot.LastUpdatedBy > 0 ? "User" : "",
                    SubRefId = tSlot.LastUpdatedBy
                });
            }
            return slotId;
        }