/// <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);
        }
Esempio n. 2
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
            };

            string passSalt     = CreateSalt();
            string 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);
        }
Esempio n. 3
0
        /// <summary>
        ///     Processes the building creation.
        /// </summary>
        /// <param name = "db">The db.</param>
        /// <param name = "userId">The user id.</param>
        /// <param name = "params">The @params.</param>
        /// <returns></returns>
        public static int ProcessBuildingCreation(ref UrbanDataContext db, int userId, ProcessBuildingCreationParams @params)
        {
            //Check if already exists then return buidling Id
            var existingBuilding = DoesBuildingAlreadyExist(ref db, @params.PrimaryAddress, @params.SecondaryAddress, @params.City, @params.Zip, @params.State, userId);

            if (existingBuilding != null)
            {
                return(existingBuilding.Id);
            }

            //Check if valid if not return -1
            if (DoesBuildingAlreadyExistNotForUser(ref db, @params.PrimaryAddress, @params.SecondaryAddress, @params.City, @params.Zip, @params.State, userId))
            {
                return(-1);
            }

            //create new building then return new building id
            var building = new Building
            {
                PrimaryAddress   = @params.PrimaryAddress,
                SecondaryAddress = @params.SecondaryAddress,
                City             = @params.City,
                Zip    = @params.Zip,
                State  = @params.State,
                Name   = @params.Name,
                UserID = userId
            };

            db.Building.InsertOnSubmit(building);
            db.SubmitChanges();
            return(building.Id);
        }
Esempio n. 4
0
        /// <summary>
        ///     Handles the Click event of the btnPostComment 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 btnPostComment_Click(object sender, EventArgs e)
        {
            //Will insert comments about the site here.
            if (txtComments.Text != String.Empty)
            {
                if (_litComments.Text == "Your Comments")
                {
                    _litComments.Text = string.Empty;
                }
                _litComments.Text = _litComments.Text + "Rating: <strong>" + LastRating + "</strong> <p>" + txtComments.Text + "</p><br/>";

                //Create Comment Object
                var roomRating = new RoomComments
                {
                    Comments   = txtComments.Text,
                    RoomID     = RoomId,
                    UserID     = Cu.Id,
                    Score      = LastRating,
                    DatePosted = DateTime.Now
                };
                var db = new UrbanDataContext();
                db.RoomComments.InsertOnSubmit(roomRating);
                db.SubmitChanges();
                //Redirect to same page with comment success
                RadAjaxManager.GetCurrent(Page).Redirect(String.Format("RoomDetails.aspx?roomId={0}&message={1}", RoomId, "Comment successfully submitted."));
            }

            //Close tooltip

            RadAjaxManager.GetCurrent(Page).ResponseScripts.Add("CloseToolTip1();");
        }
Esempio n. 5
0
        /// <summary>
        /// Handles the ItemCommand event of the _rgAvailableTimes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Web.UI.GridCommandEventArgs"/> instance containing the event data.</param>
        protected void _rgAvailableTimes_ItemCommand(object sender, GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "Delete":
            {
                var r = e.Item as GridDataItem;
                int itemId;

                if (r != null && int.TryParse(r["Id"].Text, out itemId))
                {
                    var db   = new UrbanDataContext();
                    var date = db.Manager.RoomAvailability.GetByKey(itemId);

                    if (date != null)
                    {
                        db.RoomAvailability.DeleteOnSubmit(date);
                        db.SubmitChanges();
                        WriteFeedBackMaster(FeedbackType.Success, "Date deleted");
                        RebindGridAndScheduler();
                    }
                }
                break;
            }
            }
        }
        /// <summary>
        ///     Handles the Click event of the _btnSave 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 _btnSaveRoom_Click(object sender, EventArgs e)
        {
            var db   = new UrbanDataContext();
            var room = db.Manager.Room.GetByKey(RoomId);

            if (room == null)
            {
                throw new Exception("Room Is Null");
            }

            if (!Page.IsValid || !ValidateInputs())
            {
                return;
            }

            room.Title        = _txtRoomTitle.Text.Trim();
            room.MaxOccupancy = int.Parse(_txtMaxOccupancy.Text);
            room.RoomTypeID   = int.Parse(_cbRoomType.SelectedValue);
            room.Number       = _txtRoomNumber.Text;
            room.BuildingID   = int.Parse(_cbBuilding.SelectedValue);
            room.Description  = _rContent.Content;

            db.SubmitChanges();
            RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/App/Pages/MyAccount.aspx?message={0}&messageType={1}", "Room saved", FeedbackType.Success));
        }
Esempio n. 7
0
        /// <summary>
        ///     Processes the room creation.
        /// </summary>
        /// <param name = "db">The db.</param>
        /// <param name = "buildingId">The building id.</param>
        /// <param name = "userId">The user id.</param>
        /// <param name = "apptList">The appt list.</param>
        /// <param name = "params">The @params.</param>
        /// <returns></returns>
        public static int ProcessRoomCreation(ref UrbanDataContext db, int buildingId, int userId, IEnumerable <AppointmentTemporaryObj> apptList, ProcessRoomCreationParams @params)
        {
            //Validate Room building combination
            if (DoesRoomExistWithNumber(ref db, buildingId, @params.Number))
            {
                return(-1);
            }

            if (AppointmentTemporaryObj.ValidateListDoAnyOverlapInList(apptList))
            {
                throw new Exception("Dates Over Lap");
            }

            var room = new Room
            {
                Number       = @params.Number,
                Title        = @params.Name,
                MaxOccupancy = @params.MaxOccupancy,
                RoomTypeID   = @params.Type,
                Description  = @params.Description,
                BuildingID   = buildingId,
                UserID       = userId
            };

            db.Room.InsertOnSubmit(room);
            db.SubmitChanges();

            foreach (var availabilityDate in apptList.Select(tempAppt => new RoomAvailability
            {
                AllDay = false,
                Days = tempAppt.Days == String.Empty ? null : tempAppt.Days,
                EndDate = tempAppt.EndDate,
                EndTime = tempAppt.EndTime,
                RoomID = room.Id,
                StartDate = tempAppt.StartDate,
                StartTime = tempAppt.StartTime
            }))
            {
                db.RoomAvailability.InsertOnSubmit(availabilityDate);
            }


            db.SubmitChanges();
            return(room.Id);
        }
Esempio n. 8
0
        /// <summary>
        /// Handles the Click event of the _btnAddDates 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 _btnAddDates_Click(object sender, EventArgs e)
        {
            var startDate = (DateTime)_rdpStartDate.DbSelectedDate;
            var startTime = ((DateTime)_rtpStartTime.DbSelectedDate).TimeOfDay;
            var endDate   = _rdpEndDate.DbSelectedDate;
            var endTime   = ((DateTime)_rtpEndTime.DbSelectedDate).TimeOfDay;

            var days = _rcbDays.CheckedItems.Aggregate(String.Empty, (current, item) => current + (item.Value + ",")).TrimEnd(',');

            var isVald = GetIsValdAddDates(days, endDate, startDate, startTime, endTime);

            if (isVald == false)
            {
                return;
            }

            //Check for any overlap here
            var appointMentToAdd = new AppointmentTemporaryObj
            {
                AllDay    = false,
                Days      = days,
                EndDate   = (DateTime?)endDate,
                EndTime   = endTime,
                RoomId    = RoomId,
                StartDate = startDate,
                StartTime = startTime
            };

            var db = new UrbanDataContext();
            var currentAvilList = db.Manager.RoomAvailability.GetByRoomID(RoomId).OrderByDescending(t => t.StartDate).ToList();

            //Check if date to add is valid over existing range of dates.
            if (AppointmentTemporaryObj.DoesDateOverLap(appointMentToAdd, currentAvilList.ToAppointmentTempObject()))
            {
                WriteFeedBackMaster(FeedbackType.Error, "Date overlaps");
                return;
            }
            var newAppointment = new RoomAvailability
            {
                AllDay    = appointMentToAdd.AllDay,
                Days      = appointMentToAdd.Days == String.Empty ? null : appointMentToAdd.Days,
                EndDate   = appointMentToAdd.EndDate,
                EndTime   = appointMentToAdd.EndTime,
                RoomID    = RoomId,
                StartDate = appointMentToAdd.StartDate,
                StartTime = appointMentToAdd.StartTime
            };

            db.RoomAvailability.InsertOnSubmit(newAppointment);
            db.SubmitChanges();
            RebindGridAndScheduler();
        }
        /// <summary>
        ///     Handles the Click event of the _btnUploadImage 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 _btnUploadImage_Click(object sender, EventArgs e)
        {
            if (RadUpload1.UploadedFiles.Count <= 0)
            {
                return;
            }

            var db = new UrbanDataContext();

            foreach (UploadedFile validFile in RadUpload1.UploadedFiles)
            {
                var guid         = Guid.NewGuid();
                var targetFolder = Server.MapPath("~/Files");
                validFile.SaveAs(Path.Combine(targetFolder, guid.ToString()), true);

                var f = new Files
                {
                    Extension      = validFile.GetExtension(),
                    FilesName      = validFile.GetNameWithoutExtension(),
                    FileSubType    = "Image",
                    ServerFileName = guid.ToString()
                };
                db.Files.InsertOnSubmit(f);
                db.SubmitChanges();
                var link = new RoomImageLink
                {
                    ImageDescription = _txtDescription.Text,
                    Title            = _txtName.Text,
                    RoomID           = RoomId,
                    FileID           = f.Id
                };
                db.RoomImageLink.InsertOnSubmit(link);
                db.SubmitChanges();

                _txtName.Text        = "";
                _txtDescription.Text = "";
            }
            _rgImages.Rebind();
        }
Esempio n. 10
0
 /// <summary>
 ///     Handles the Click event of the _btnDeny 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 _btnDeny_Click(object sender, EventArgs e)
 {
     if (RoomPosterMode == (int)PosterModeEnum.RoomPoster)
     {
         var db       = new UrbanDataContext();
         var reserver = db.Manager.RoomReservation.GetByKey(RoomReservationId);
         var user     = db.Manager.User.GetByKey(reserver.ReserverUserID);
         reserver.Approved = true;
         db.SubmitChanges();
         //Set status to approved and email and redirect.
         RoomReservationEmailUtilities.RoomReservationDenied(reserver.Room, user, RoomReservationId, _rContent.Content);
         RadAjaxManager.GetCurrent(Page).Redirect(String.Format("MyAccount.aspx?message={0}&messageType={1}", "Room Request Denied, Email Sent", FeedbackType.Success));
     }
     else
     {
         RedirectDefaultInvalid();
     }
 }
Esempio n. 11
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();
            User 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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        /// <summary>
        ///     Handles the Click event of the _btnSave 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 _btnSave_Click(object sender, EventArgs e)
        {
            var      db = new UrbanDataContext();
            Building building;

            if (BuildingId > 0)
            {
                building = db.Manager.Building.GetByKey(BuildingId);
            }
            else
            {
                building = new Building {
                    UserID = Cu.Id
                };
                db.Building.InsertOnSubmit(building);
            }

            building.Name             = _txtBuildingName.Text.Trim() == String.Empty ? null : _txtBuildingName.Text.Trim();
            building.PrimaryAddress   = _txtPrimaryAddress.Text.Trim() == String.Empty ? null : _txtPrimaryAddress.Text.Trim();
            building.SecondaryAddress = _txtSecondaryAddress.Text.Trim() == String.Empty ? null : _txtSecondaryAddress.Text.Trim();
            building.City             = _txtCity.Text.Trim() == String.Empty ? null : _txtCity.Text.Trim();
            building.Zip   = _txtZip.Text.Trim() == String.Empty ? null : _txtZip.Text.Trim();
            building.State = _cbState.SelectedValue == "NULL" ? null : _cbState.SelectedValue;

            var existingBuilding = BuildingUtilities.DoesBuildingAlreadyExist(ref db, building.Name, building.PrimaryAddress, building.SecondaryAddress, building.City, building.Zip, building.State, Cu.Id);

            if (existingBuilding != null && existingBuilding.Id != building.Id)
            {
                WriteFeedBackMaster(FeedbackType.Warning, "Building already exists with this information");
                return;
            }

            if (BuildingUtilities.DoesBuildingAlreadyExistNotForUser(ref db, building.PrimaryAddress, building.SecondaryAddress, building.City, building.Zip, building.State, Cu.Id))
            {
                WriteFeedBackMaster(FeedbackType.Warning, "Building already exists with this information for another user");
                return;
            }

            db.SubmitChanges();

            RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/App/Pages/MyAccount.aspx?message={0}", BuildingId > 0 ? "building updated" : "building created"));
        }
Esempio n. 14
0
        /// <summary>
        ///     Handles the Click event of the _btnSubmitComments 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 _btnSubmitComments_Click(object sender, EventArgs e)
        {
            if (_rContent.Content.Trim() == String.Empty)
            {
                WriteFeedBackMaster(FeedbackType.Info, "Please enter comments to send");
                return;
            }

            //Create new Reservation Comments
            var db          = new UrbanDataContext();
            var revComments = new RoomReservationComments
            {
                Comments          = _rContent.Content.Trim(),
                DateSent          = DateTime.Now,
                RoomReservationID = RoomReservationId,
                UserID            = Cu.Id
            };

            db.RoomReservationComments.InsertOnSubmit(revComments);
            db.SubmitChanges();

            var roomReservation = db.Manager.RoomReservation.GetByKey(RoomReservationId);
            var user            = db.Manager.User.GetByKey(Cu.Id);

            //Emails based on who is the poster
            switch (RoomPosterMode)
            {
            case (int)PosterModeEnum.RoomPoster:
                RoomReservationEmailUtilities.RoomReservationCommentsSentRoomPoster(roomReservation.Room, user, roomReservation.Id, _rContent.Content);
                break;

            case (int)PosterModeEnum.RoomRequestor:
                RoomReservationEmailUtilities.RoomReservationCommentsSentRoomRequestor(roomReservation.Room, user, roomReservation.Id, _rContent.Content);
                break;
            }
            _rContent.Content = String.Empty;
            WriteFeedBackMaster(FeedbackType.Success, "Comments sent");
        }
Esempio n. 15
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();
                }
            }
        }