예제 #1
0
 /// <summary>
 ///     Gets all.
 /// </summary>
 /// <returns></returns>
 public static IEnumerable<RadComboBoxItem> GetAll(bool insertEmpty)
 {
     var db = new UrbanDataContext();
     var list = (from d in db.RoomType orderby d.Name select new RadComboBoxItem {Text = d.Name, Value = d.Id.ToString()}).ToList();
     if (insertEmpty) list.Insert(0, new RadComboBoxItem("(None)", "NULL"));
     return list;
 }
예제 #2
0
 /// <summary>
 ///     Raises the <see cref = "E:System.Web.UI.Control.Init" /> event to initialize the page.
 /// </summary>
 /// <param name = "e">An <see cref = "T:System.EventArgs" /> that contains the event data.</param>
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     if (!IsPostBack)
     {
         var db = new UrbanDataContext();
         //Gets the first and last day for the month
         switch(Type)
         {
             case 1:
                 {
                     ViewState["Appointments"] = AppointmentUtilities.GetAppointmentObjectsByDateRangeAndRoomId(ref db, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1), Utilities.GetQueryStringInt("roomId"));
                     Page.Title = "Room Details";
                     break;
                 }
             case 2:
                 {
                     ViewState["Appointments"] = AppointmentUtilities.GetAllReservedObjectsByDateRangeAndUserId(ref db, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1), Cu.Id);
                     Page.Title = "Up Comming Events";
                     break;
                 }
             case 3:
                 {
                     ViewState["Appointments"] = AppointmentUtilities.GetAllReservedObjectsByReservationId(ref db, Utilities.GetQueryStringInt("RoomReservationID"));
                     Page.Title = "Reservation";
                     break;
                 }
         }
     }
     _rsReservations.DataSource = Appointments;
 }
예제 #3
0
        /// <summary>
        ///     Creates the user.
        /// </summary>
        /// <param name = "info">The info.</param>
        /// <param name = "password">The password.</param>
        /// <returns></returns>
        public static bool CreateUser(User info, string password)
        {
            var db = new UrbanDataContext();

            //User Item
            var u = new User
                        {
                            ActivationGuid = info.ActivationGuid,
                            City = info.City,
                            DateCreated = DateTime.Now,
                            Email = info.Email,
                            FirstName = info.FirstName,
                            LastName = info.LastName,
                            IsAdmin = false,
                            PhoneNumber = info.PhoneNumber,
                            PrimaryAddress = info.PrimaryAddress,
                            Zip = info.Zip
                        };

            var passSalt = CreateSalt();
            var passwordHash = CreatePasswordHash(password, passSalt);

            u.Password = passwordHash;
            u.PasswordSalt = passSalt;
            db.User.InsertOnSubmit(u);
            db.SubmitChanges();

            //Send Email With firm information user ID, and the new password.
            //User_EmailTemplate.NewUserAccount(u.Id, (int)c.FirmID, password);

            return true;
        }
예제 #4
0
        ///// <summary>
        ///// Gets all for search.
        ///// </summary>
        ///// <param name="zip">The zip.</param>
        ///// <param name="city">The city.</param>
        ///// <param name="state">The state.</param>
        ///// <returns></returns>
        //public List<Room> GetAllForSearch(string zip, string city, string state)
        //{
        //    return (from d in Entity
        //            where (zip != String.Empty && d.Building.Zip.Trim() == zip.Trim()) ||
        //                  (city != String.Empty && d.Building.City.Trim() == city.Trim()) ||
        //                  (state != String.Empty && d.Building.State.Trim() == state.Trim())
        //            select d).ToList();
        //}


        /// <summary>
        /// Gets all for search.
        /// </summary>
        /// <param name="zip">The zip.</param>
        /// <param name="city">The city.</param>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public List <Room> GetAllForSearch(string zip, string city, string state, DateTime?startDate, DateTime?endDate)
        {
            var rList = (from d in Entity
                         where (zip == String.Empty || d.Building.Zip.Trim() == zip.Trim()) &&
                         (city == String.Empty || d.Building.City.Trim() == city.Trim()) &&
                         (state == String.Empty || d.Building.State.Trim() == state.Trim())
                         select d).ToList();

            if (startDate == null || endDate == null)
            {
                return(rList);
            }

            var returnList      = new List <Room>();
            UrbanDataContext db = new UrbanDataContext();

            foreach (var room in rList)
            {
                var apptList = UrbanSchedulerProject.Code.Utilities.AppointmentUtilities.GetAppointmentObjectsByDateRangeAndRoomId(ref db, (DateTime)startDate, (DateTime)endDate, room.Id);
                if (apptList.Count() > 0)
                {
                    returnList.Add(room);
                }
            }
            return(returnList);
        }
예제 #5
0
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            var db = new UrbanDataContext();
            var manager = new UrbanDataManager(db);

            RadGrid1.DataSource = (from u in db.User
                                   select u).ToList();
        }
예제 #6
0
 /// <summary>
 ///     Raises the <see cref = "E:System.Web.UI.Control.Init" /> event to initialize the page.
 /// </summary>
 /// <param name = "e">An <see cref = "T:System.EventArgs" /> that contains the event data.</param>
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     if (!IsPostBack)
     {
         var db = new UrbanDataContext();
         ViewState["Appointments"] = AppointmentUtilities.GetAppointmentObjectsByDateRangeAndRoomId(ref db, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1), Utilities.GetQueryStringInt("roomId"));
     }
     _rsReservations.DataSource = Appointments;
 }
 public string ListUsers()
 {
     var db = new UrbanDataContext();
     string UserListString = "";
     List<User> usersList = (from u in db.User select u).ToList();
     foreach (User user in usersList)
     {
         UserListString += user.Id + ";";
     }
     return UserListString;
 }
예제 #8
0
 /// <summary>
 ///   Logins the specified user name.
 /// </summary>
 /// <param name = "userName">Name of the user.</param>
 /// <param name = "password">The password.</param>
 /// <returns></returns>
 public static bool Login(string userName, string password)
 {
     var db = new UrbanDataContext();
     User c = db.Manager.User.GetUserByEmail(userName);
     if (c != null && c.IsUserAuthenticated != null && (bool) c.IsUserAuthenticated)
     {
         if (DoesPassMatch(password, c.PasswordSalt, c.Password))
             return true;
         return false;
     }
     return false;
 }
예제 #9
0
        /// <summary>
        ///     Return Distinct City Objects
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<CityObject> GetDistinctCitiesByState(string state)
        {
            var db = new UrbanDataContext();
            var cList = ((from d in db.Room where d.Building.State == state  select new { d.Building.City }).Distinct().AsEnumerable().Select(p => new CityObject { Text = p.City, Value = p.City })).Distinct().ToList();

            cList.Insert(0, new CityObject
            {
                Text = "(None)",
                Value = "NULL"
            });
            return cList;
        }
 /// <summary>
 ///     Gets all reserved objects by date range and user id.
 /// </summary>
 /// <param name = "db">The db.</param>
 /// <param name = "startDate">The start date.</param>
 /// <param name = "endDate">The end date.</param>
 /// <param name = "userId">The user id.</param>
 /// <returns></returns>
 public static IEnumerable<AppointmentObj> GetAllReservedObjectsByDateRangeAndUserId(ref UrbanDataContext db, DateTime startDate, DateTime endDate, int userId)
 {
     var rList = RoomReservationDatesUtilities.GetAppointmentObjByStartDateEndDateUserId(ref db, startDate, endDate, userId);
     return rList.Select(r => new AppointmentObj
                                  {
                                      Busy = true,
                                      Days = r.Days,
                                      End = r.End,
                                      Start = r.Start,
                                      Subject = r.Subject
                                  }).ToList();
 }
 /// <summary>
 /// Gets all reserved objects by date range and user id.
 /// </summary>
 /// <param name="db">The db.</param>
 /// <param name="reservationId">The reservation id.</param>
 /// <returns></returns>
 public static IEnumerable<AppointmentObj> GetAllReservedObjectsByReservationId(ref UrbanDataContext db, int reservationId)
 {
     var rList = RoomReservationDatesUtilities.GetAppointmentObjByUserId(ref db, reservationId);
     return rList.Select(r => new AppointmentObj
     {
         Busy = true,
         Days = r.Days,
         End = r.End,
         Start = r.Start,
         Subject = r.Subject
     }).ToList();
 }
        /// <summary>
        ///     Gets the appointment obj by start date end date room id.
        /// </summary>
        /// <param name = "db">The db.</param>
        /// <param name = "startDate">The start date.</param>
        /// <param name = "endDate">The end date.</param>
        /// <param name = "roomId">The room id.</param>
        /// <returns></returns>
        public static IEnumerable<AppointmentObj> GetAppointmentObjByStartDateEndDateRoomId(ref UrbanDataContext db, DateTime startDate, DateTime endDate, int roomId)
        {
            var rList = (from d in db.RoomReservationDates
                         where d.RoomReservation.RoomID == roomId && d.StartDate >= startDate && d.EndDate <= endDate
                         select new AppointmentObj("Reserved", d.StartDate, d.EndDate, "", "", "", d.RoomReservation.ReserverUserID, true, d.Id)).ToList();

            if (rList.Any(t => t.Start >= t.End || t.End <= t.Start))
            {
                throw new Exception("Date Ranges Are Not Valid");
            }

            return rList;
        }
예제 #13
0
 /// <summary>
 ///     Gets the by user id.
 /// </summary>
 /// <param name = "userId">The user id.</param>
 /// <param name = "insertEmpty">if set to <c>true</c> [insert empty].</param>
 /// <returns></returns>
 public static IEnumerable<RadComboBoxItem> GetByUserId(int userId, bool insertEmpty)
 {
     var db = new UrbanDataContext();
     var list = (from d in db.Building
                 where d.UserID == userId
                 orderby d.Name
                 select new RadComboBoxItem
                            {
                                Text = d.Name ?? d.PrimaryAddress,
                                Value = d.Id.ToString()
                            }).ToList();
     if (insertEmpty) list.Insert(0, new RadComboBoxItem("(None)", "NULL"));
     return list;
 }
예제 #14
0
        /// <summary>
        ///     Checks the activate user.
        /// </summary>
        /// <param name = "key">The key.</param>
        /// <returns></returns>
        public static int CheckActivateUser(Guid key)
        {
            var db = new UrbanDataContext();
            var user = db.Manager.User.GetByActivationGuid(key);
            if (user == null)
                return -1;

            if (user.IsUserAuthenticated != null && (bool) user.IsUserAuthenticated)
                return 0;

            user.IsUserAuthenticated = true;
            db.SubmitChanges();
            return 1;
        }
예제 #15
0
        protected void _btnEmailTest_Click(object sender, EventArgs e)
        {
            var db = new UrbanDataContext();
            User user = db.Manager.User.GetByKey(1);
            var keys = new List<KeyValuePair<string, string>>();
            keys.Add(new KeyValuePair<string, string>("{!MainTitleHtml}", "Account Created"));
            keys.Add(new KeyValuePair<string, string>("{!Subtitle01Html}", "Action Required"));
            keys.Add(new KeyValuePair<string, string>("{!Subtitle01TextHtml}",
                                                      "Congratulations on creating your account activation is still required. Please follow the links bellow."));
            keys.Add(new KeyValuePair<string, string>("{!LinkHtml}", "http://UrbanScheduler.com"));
            keys.Add(new KeyValuePair<string, string>("{!LinkTextHtml}", "Click Here To Activate Account"));
            keys.Add(new KeyValuePair<string, string>("{!FormPerson}", "UrbanScheduler System"));

            EmailTemplateUtilities.EmailFromFromMaster(keys, "Test email", user, new List<int>());
            //EmailUti1lities.SendEmail("Test Email", "Test Email", "Test Email", "Nate Email", "*****@*****.**", new List<int>());
        }
        /// <summary>
        ///     Creates the room reservation.
        /// </summary>
        /// <param name = "userId">The user id.</param>
        /// <param name = "roomId">The room id.</param>
        /// <param name = "comments">The comments.</param>
        /// <returns></returns>
        public static int CreateRoomReservation(int userId, int roomId, string comments, List<ReserveRoomTempObject> timeList)
        {
            if (timeList.Count <= 0)
                return -1;

            var db = new UrbanDataContext();

            var reservation = new RoomReservation
                                  {
                                      Approved = null,
                                      ReserverUserID = userId,
                                      RoomID = roomId,
                                      RequestedDate = DateTime.Now
                                  };
            db.RoomReservation.InsertOnSubmit(reservation);
            db.SubmitChanges();
            //Insert Dates

            foreach (var rTime in timeList.Select(r => new RoomReservationDates
                                                           {
                                                               AllDay = false, 
                                                               EndDate = r.Date.Add(r.End),
                                                               StartDate = r.Date.Add(r.Start),
                                                               RoomReservationID = reservation.Id
                                                           }))
            {
                db.RoomReservationDates.InsertOnSubmit(rTime);
            }

            if (comments.Trim() != string.Empty)
            {
                var revComments = new RoomReservationComments
                                      {
                                          Comments = comments.Trim(),
                                          DateSent = DateTime.Now,
                                          RoomReservationID = reservation.Id,
                                          UserID = userId
                                      };
                db.RoomReservationComments.InsertOnSubmit(revComments);
            }
            db.SubmitChanges();
            var room = db.Manager.Room.GetByKey(roomId);
            var user = db.Manager.User.GetByKey(room.UserID);
            RoomReservationEmailUtilities.InitiateRoomReservationRequest(room, user, reservation.Id, comments);
            return 1;
        }
예제 #17
0
        /// <summary>
        ///     Initializes a new instance of the <see cref = "CurrentUserObj" /> class.
        ///     Will save in  session and authenticate
        /// </summary>
        /// <param name = "email">The email.</param>
        public CurrentUserObj(string email)
        {
            if (email == String.Empty)
                throw new ArgumentException("username == String.Empty", "email");

            TraceUtilities.WriteTrace(true);
            var db = new UrbanDataContext();
            var person = db.Manager.User.GetUserByEmail(email);
            //Loads information for first and last name from contacts if they exist.)
            if (person == null)
                throw new NullReferenceException("Contact associated with the user is null for username:" + email + Environment.StackTrace);

            Id = person.Id;
            Email = person.Email;

            TraceUtilities.WriteTrace(false);
        }
        /// <summary>
        ///     Handles the Load event of the Page control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            InitPage("Edit Room Details", MainTabs.MyAccount);
            if (Page.IsPostBack) return;

            RoomId = Utilities.GetQueryStringInt("RoomId");
            if (RoomId <= 0)
                RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/Default.aspx?message={0}&messageType={1}", "Invalid room", FeedbackType.Warning));
            var db = new UrbanDataContext();
            var room = db.Manager.Room.GetByKey(RoomId);

            if (CurrentUserUtilities.GetCuIdSafely() <= 0 || room == null || room.UserID != Cu.Id)
            {
                RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/Default.aspx?message={0}&messageType={1}", "Invalid room", FeedbackType.Warning));
            }
            _cbRoomType.Items.AddRange(RoomTypeUtilties.GetAll(false));
            _cbBuilding.Items.AddRange(BuildingUtilities.GetByUserId(Cu.Id, false));
            LoadPageFields(room);
        }
        /// <summary>
        ///     Gets the appointment objects by date range and room id.
        /// </summary>
        /// <param name = "db">The db.</param>
        /// <param name = "startDate">The start date.</param>
        /// <param name = "endDate">The end date.</param>
        /// <param name = "roomId">The room id.</param>
        /// <returns></returns>
        public static IEnumerable<AppointmentObj> GetAppointmentObjectsByDateRangeAndRoomId(ref UrbanDataContext db, DateTime startDate, DateTime endDate, int roomId)
        {
            var apptList = new List<AppointmentObj>();

            //Retrieve Reserved Dates For room and date range
            var rList = RoomReservationDatesUtilities.GetAppointmentObjByStartDateEndDateRoomId(ref db, startDate, endDate, roomId);
            //Retrieve Dates with recurring for start and end date with roomId
            var aList = RoomAvailabilityUtilities.GetAppointmentObjsWithRecurring(ref db, startDate, endDate, roomId);

            //Deal with date duplicates
            var processAvailList = ProcessAvailabilityDateOverLap(rList, aList);

            //Add Dates to list
            apptList.AddRange(rList);
            apptList.AddRange(processAvailList);

            //Order List by start date
            return apptList.OrderBy(t => t.Start).ToList();
        }
        /// <summary>
        ///     Builds the comments for room.
        /// </summary>
        /// <param name = "roomId">The room id.</param>
        /// <returns></returns>
        public static string BuildCommentsForRoom(int roomId)
        {
            var sb = new StringBuilder();
            var db = new UrbanDataContext();
            var commentList = db.Manager.RoomComments.GetByRoomID(roomId).OrderByDescending(t => t.DatePosted);
            var count = 0;
            foreach (var c in commentList)
            {
                if (count > 0)
                    sb.Append("<br />");
                sb.Append(String.Format("<strong>Rating: {0} / 5 </strong><br />", c.Score));
                if(c.DatePosted != null)
                    sb.AppendLine(String.Format("<strong>Date Posted: {0} </strong><br />", ((DateTime)c.DatePosted).ToShortDateString()));
                sb.AppendLine(String.Format("<strong>Comments:</strong> {0}<br />", c.Comments));
                count++;
            }


            return sb.ToString();
        }
        /// <summary>
        ///     Gets the rating for room.
        /// </summary>
        /// <param name = "roomId">The room id.</param>
        /// <returns></returns>
        public static int GetRatingForRoomAndComments(int roomId)
        {
            var db = new UrbanDataContext();
            var commentList = db.Manager.RoomComments.GetByRoomID(roomId).ToList();

            var sum = commentList.Sum(t => t.Score);
            var num = commentList.Count();

            if (num <= 0)
                return 0;

            try
            {
                return (int) sum/num;
            }
            catch (DivideByZeroException)
            {
                return 0;
            }
        }
예제 #22
0
        /// <summary>
        ///     Handles the Load event of the Page control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            BuildingId = Utilities.GetQueryStringInt("BuildingId");

            InitPage(BuildingId > 0 ? "Edit Building Details" : "Create Building", MainTabs.MyAccount);

            if (Page.IsPostBack) return;

            if (BuildingId < 0)
                RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/Default.aspx?message={0}&messageType={1}", "Invalid Building", FeedbackType.Error));
            var db = new UrbanDataContext();
            var building = db.Manager.Building.GetByKey(BuildingId);

            if (CurrentUserUtilities.GetCuIdSafely() <= 0 || (building != null && building.UserID != Cu.Id))
            {
                RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/Default.aspx?message={0}&messageType={1}", "Invalid Building", FeedbackType.Error));
            }
            _cbState.LoadXml(Utilities.GetXmlForPath(Utilities.StatePathWithNoneXml));
            LoadPageFields(building);
        }
예제 #23
0
        ///// <summary>
        ///// Gets all for search.
        ///// </summary>
        ///// <param name="zip">The zip.</param>
        ///// <param name="city">The city.</param>
        ///// <param name="state">The state.</param>
        ///// <returns></returns>
        //public List<Room> GetAllForSearch(string zip, string city, string state)
        //{
        //    return (from d in Entity
        //            where (zip != String.Empty && d.Building.Zip.Trim() == zip.Trim()) ||
        //                  (city != String.Empty && d.Building.City.Trim() == city.Trim()) ||
        //                  (state != String.Empty && d.Building.State.Trim() == state.Trim())
        //            select d).ToList();
        //}


        /// <summary>
        /// Gets all for search.
        /// </summary>
        /// <param name="zip">The zip.</param>
        /// <param name="city">The city.</param>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public List<Room> GetAllForSearch(string zip, string city, string state, DateTime? startDate, DateTime? endDate)
        {
            var rList =  (from d in Entity
                    where (zip == String.Empty || d.Building.Zip.Trim() == zip.Trim()) &&
                          (city == String.Empty || d.Building.City.Trim() == city.Trim()) &&
                          (state == String.Empty || d.Building.State.Trim() == state.Trim())
                    select d).ToList();

            if (startDate == null || endDate == null)
                return rList;

            var returnList = new List<Room>();
            UrbanDataContext db = new UrbanDataContext();
            foreach(var room in rList)
            {
                var apptList = UrbanSchedulerProject.Code.Utilities.AppointmentUtilities.GetAppointmentObjectsByDateRangeAndRoomId(ref db, (DateTime)startDate, (DateTime)endDate, room.Id);
                  if(apptList.Count() > 0)
                      returnList.Add(room);
            }
            return returnList;
        }
예제 #24
0
        /// <summary>
        ///     Sends email
        ///     Attaches Files by Id in the DocList
        /// </summary>
        /// <param name = "html">The HTML.</param>
        /// <param name = "text">The text.</param>
        /// <param name = "subject">The subject.</param>
        /// <param name = "toName">To name.</param>
        /// <param name = "toEmail">To email.</param>
        /// <param name = "cc">The cc.</param>
        public static void SendEmail(string html, string text, string subject, string toName, string toEmail, IEnumerable<int> cc)
        {
            if (string.IsNullOrEmpty(toEmail)) return;
            var db = new UrbanDataContext();
            const string email = "*****@*****.**";
            const string emailSystem = "UrbanScheduler";

            var smtp = new SmtpClient(Utilities.IsSiteLocal() ? GlobalServer : GlobalLiveServer);
            var message = new MailMessage(new MailAddress(email, emailSystem), new MailAddress(toEmail, toName))
                              {Subject = subject};

            foreach (var userCc in cc.Select(i => db.Manager.User.GetByKey(i)).Where(userCc => !string.IsNullOrEmpty(userCc.Email)))
            {
                message.CC.Add(new MailAddress(userCc.Email, userCc.FirstName + " " + userCc.LastName));
            }

            //Create Views
            var htmlView = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
            var textView = AlternateView.CreateAlternateViewFromString(text, null, "text/plain");

            message.AlternateViews.Add(textView);
            message.AlternateViews.Add(htmlView);

            if (Utilities.IsSiteLocal())
            {
                var userName = ConfigurationManager.AppSettings["gmailAddress"];
                var password = ConfigurationManager.AppSettings["gmailPass"];
                var cred = new NetworkCredential(userName, password);
                smtp.UseDefaultCredentials = false;
                smtp.EnableSsl = true;
                smtp.Credentials = cred;
                smtp.Port = 587;
            }

            db.SubmitChanges();
            smtp.Timeout = 300000;
            smtp.Send(message);
        }
        /// <summary>
        /// End date needs to have time = 23 and start time = 0 or 1
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="roomId">The room id.</param>
        /// <returns></returns>
        public static List<AppointmentObj> GetAppointmentObjsWithRecurring(ref UrbanDataContext db, DateTime startDate, 
            DateTime endDate, int roomId)
        {
            var apptList = new List<AppointmentObj>();
            var aList = db.Manager.RoomAvailability.GetByRoomAndDateRange(startDate, endDate, roomId);

            if (aList.Any(t => t.EndDate != null && (t.StartDate.Add(t.StartTime) >= ((DateTime) t.EndDate).Add(t.EndTime) || 
                ((DateTime) t.EndDate).Add(t.EndTime) <= t.StartDate.Add(t.StartTime))))
            {
                throw new Exception("Date Ranges Are Not Valid");
            }

            foreach (var date in aList)
            {
                if (date.Days == null) // Non Recurring Dates
                {
                    if (date.EndDate == null) continue;
                   
                    if (date.EndDate > date.StartDate.Date)
                    {
                        var reccuringApptDates = CalculateRecurringFromAvailble(date, (DateTime)date.EndDate).Distinct();
                        apptList.AddRange(reccuringApptDates);
                    }
                    else apptList.Add(new AppointmentObj("Available", Utilities.CombineDateAndTime(date.StartDate, date.StartTime),
                        Utilities.CombineDateAndTime(date.EndDate, date.EndTime), "", "", "", date.Room.UserID, false, date.Id));
                }
                else // Recurring Dates
                {
                    var endingDate = endDate; //If end date is null use end date requested
                    if (date.EndDate != null && date.EndDate <= endDate)
                        endingDate = (DateTime) date.EndDate;

                    var reccuringApptDates = CalculateRecurringFromAvailble(date, endingDate).Distinct();
                    apptList.AddRange(reccuringApptDates);
                }
            }
            return apptList;
        }
예제 #26
0
        /// <summary>
        ///     Handles the Click event of the _btnSearch control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected void _btnSearch_Click(object sender, EventArgs e)
        {
            if (_txtZip.Text.Trim() == String.Empty && _cbCity.SelectedValue == "NULL" && _cbState.SelectedValue == "NULL")
            {
                WriteFeedBackMaster(FeedbackType.Warning, "Please select at least one field to search by");
                return;
            }

            var zip = _txtZip.Text.Trim() != String.Empty ? _txtZip.Text.Trim() : String.Empty;
            var city = _cbCity.SelectedValue != "NULL" ? _cbCity.SelectedValue : String.Empty;
            var state = _cbState.SelectedValue != "NULL" ? _cbState.SelectedValue : String.Empty;
            var startDate = (DateTime?)_rdpStart.DbSelectedDate;
            var endDate = (DateTime?)_rdpEnd.DbSelectedDate;

            var db = new UrbanDataContext();
            //Loads all rooms based on search queries
            var list = db.Manager.Room.GetAllForSearch(zip, city, state,startDate,endDate);
            _rgSearchResults.DataSource = list;
            _rgSearchResults.Rebind();

            if (list.Count <= 0) return;
            _btnViewResultsOnMap.Visible = true;
            _btnViewResultsOnMap.Enabled = true;
        }
예제 #27
0
        /// <summary>
        ///     Handles the Click event of the _btnCreateAccount control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected void _btnCreateAccount_Click(object sender, EventArgs e)
        {
            if (IsInputValid() == false)
                return;

            var db = new UrbanDataContext();
            var user = db.Manager.User.GetUserByEmail(_txtEmail.Text.Trim());
            if (user != null)
            {
                WriteFeedBackMaster(FeedbackType.Warning, "Email address already in use.");
                return;
            }

            //Create new user
            var u = new User
                        {
                            ActivationGuid = Guid.NewGuid(),
                            DateCreated = DateTime.Now,
                            FirstName = _txtFirstName.Text.Trim(),
                            LastName = _txtLastName.Text.Trim(),
                            Email = _txtEmail.Text.Trim()
                        };

            //Email new user and verify success
            if (UserUtilities.CreateUser(u, _txtPassword.Text.Trim()))
            {
                UserEmailUtilities.NewUserAccount(u);
                WriteFeedBackMaster(FeedbackType.Success, "Account Created Succesfully");
                var ajaxManager = RadAjaxManager.GetCurrent(Page);
                ajaxManager.ResponseScripts.Add("Close();");
            }
            else
            {
                WriteFeedBackMaster(FeedbackType.Error, "Account Creation Error");
            }
        }
예제 #28
0
        /// <summary>
        ///     Verifies the required fields selected.
        /// </summary>
        /// <returns></returns>
        private int VerifyRequiredFieldsSelected()
        {
            //Verify Room Values
            if (_txtRoomNumber.Text.Trim() == String.Empty || _txtRoomTitle.Text.Trim() == String.Empty || _txtMaxOccupancy.Text == String.Empty || _cbRoomType.SelectedValue == "NULL")
                return -1;
            if (_txtPrimaryAddress.Text.Trim() == String.Empty || _txtCity.Text.Trim() == String.Empty || _txtZip.Text.Trim() == String.Empty || _cbState.SelectedValue == "NULL")
                return -1;

            var db = new UrbanDataContext();
            //Building Exists for another user check
            if (BuildingUtilities.DoesBuildingAlreadyExistNotForUser(ref db, _txtPrimaryAddress.Text.Trim(), _txtSecondaryAddress.Text.Trim(), _txtCity.Text.Trim(), _txtZip.Text.Trim(), _cbState.SelectedValue, Cu.Id))
                return -2;

            var existingBuilding = BuildingUtilities.DoesBuildingAlreadyExist(ref db, _txtPrimaryAddress.Text.Trim(), _txtSecondaryAddress.Text.Trim(), _txtCity.Text.Trim(), _txtZip.Text.Trim(), _cbState.SelectedValue, Cu.Id);

            if (existingBuilding != null)
            {
                //return existingBuilding.Id;
                if (RoomUtilities.DoesRoomExistWithNumber(ref db, existingBuilding.Id, _txtRoomNumber.Text.Trim()))
                {
                    return -3;
                }
            }

            return 1;
        }
예제 #29
0
        /// <summary>
        ///     Handles the Click event of the _btnCreateRoom control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected void _btnCreateRoom_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid) return;

            var db = new UrbanDataContext();

            //Verify All sections from user are valid
            var validationCheck = VerifyRequiredFieldsSelected();
            switch (validationCheck)
            {
                case -1:
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Please fill in required fields");
                        return;
                    }
                case -2:
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Building already exists with this address information");
                        return;
                    }
                case -3:
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Room already exists for this building and room number");
                        return;
                    }
                case 1:
                    {
                        break;
                    }
            }

            try
            {
                db.Connection.Open();
                _transac = db.Connection.BeginTransaction();
                db.Transaction = _transac;

                //Building Creation
                var buildingCreateParams = GetBuildingCreateParams();

                var buidlingResult = BuildingUtilities.ProcessBuildingCreation(ref db, Cu.Id, buildingCreateParams);
                if (buidlingResult != -1)
                {
                    //Room Creation
                    var roomCreateParams = GetRoomCreateParams();
                    var roomResult = RoomUtilities.ProcessRoomCreation(ref db, buidlingResult, Cu.Id, AvailabilityList, roomCreateParams);
                    if (roomResult == -1)
                    {
                        WriteFeedBackMaster(FeedbackType.Warning, "Room already exists with this number for this building please select another.");
                        _transac.Rollback();
                    }
                    else
                    {
                        //_transac.Rollback();
                        _transac.Commit();
                        //Move every temp image to full image
                        foreach (var file in ImageList)
                        {
                            var filesTemp = Server.MapPath("~/FilesTemp");
                            var imageToCopy = Path.Combine(filesTemp, file.ImageUrl);
                            var files = Server.MapPath("~/Files");
                            var imagePathToCopy = Path.Combine(files, file.ImageUrl);

                            File.Copy(imageToCopy, imagePathToCopy);

                            var f = new Files
                                        {
                                            Extension = file.Extension,
                                            FilesName = file.FileName,
                                            FileSubType = "Image",
                                            ServerFileName = file.ImageUrl
                                        };
                            db.Files.InsertOnSubmit(f);
                            db.SubmitChanges();
                            var link = new RoomImageLink
                                           {
                                               ImageDescription = file.Description,
                                               Title = file.Title,
                                               RoomID = roomResult,
                                               FileID = f.Id
                                           };
                            db.RoomImageLink.InsertOnSubmit(link);
                            db.SubmitChanges();
                        }


                        RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/App/Pages/MyAccount.aspx?message={0}", ("Room " + _txtRoomNumber.Text + " created")));
                    }
                }
                else
                {
                    WriteFeedBackMaster(FeedbackType.Warning, "This address information already eixsts for a different user. Please modify and resubmit");
                    _transac.Rollback();
                }
            }
            catch (Exception)
            {
                if (_transac != null)
                    _transac.Rollback();
                throw;
            }
            finally
            {
                if (db.Connection.State == ConnectionState.Open)
                    db.Connection.Close();
            }
        }
예제 #30
0
        /// <summary>
        ///     Handles the SelectedIndexChanged event of the _cbBuilding control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs" /> instance containing the event data.</param>
        protected void _cbBuilding_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            int itemId;
            if (!int.TryParse(e.Value, out itemId) || itemId <= 0) return;
            var db = new UrbanDataContext();
            var building = db.Manager.Building.GetByKey(itemId);
            if (building == null)
                throw new NullReferenceException("building is null with itemId : " + itemId);

            _txtPrimaryAddress.Text = building.PrimaryAddress;
            _txtSecondaryAddress.Text = building.SecondaryAddress;
            _txtCity.Text = building.City;
            _txtZip.Text = building.Zip;
            _txtBuildingName.Text = building.Name;

            var li = _cbState.FindItemByValue(building.State);
            if (li != null) li.Selected = true;
        }
예제 #31
0
 /// <summary>
 ///     Handles the NeedDataSource event of the _rgMyRooms control.
 /// </summary>
 /// <param name = "sender">The source of the event.</param>
 /// <param name = "e">The <see cref = "Telerik.Web.UI.GridNeedDataSourceEventArgs" /> instance containing the event data.</param>
 protected void _rgMyRooms_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
 {
     var db = new UrbanDataContext();
     _rgMyRooms.DataSource = db.Manager.Room.GetByUserId(Cu.Id);
 }