Пример #1
0
 public JsonResult SaveContact(ContactInfo info)
 {
     var helper = ServiceProvider.Resolve<StorageHelper>();
     helper.AddRequesterSubmission(info.RequesterID, info);
     return Json(new { result = "success" });
 }
Пример #2
0
 public HomeViewModel()
 {
     Metadata = new HomeMetadataViewModel();
     Info = new ContactInfo();
 }
 public void SaveContact(ContactInfo info)
 {
     // do nothing. saving. but not really.
 }
Пример #4
0
 public void NotifySave(ContactInfo info)
 {
     string content = info.ToString();
     SendEmail("*****@*****.**", string.Format("Student Registered: {0}", info.FullName), content);
 }
Пример #5
0
        //[TestMethod]
        //public void DeleteAllButDefault()
        //{
        //    var helper = new StorageHelper();
        //    var all = helper.GetAllMetadata().Where(q => q.Header.Alias == SchoolMetadata.DefaultAlias).Take(1).ToArray();
        //    Assert.AreEqual(all.Length, 1);
        //    helper.UpdateAllMetadata(all);
        //}
        //[TestMethod]
        public void Create_Requester_Submission()
        {
            var info = new ContactInfo {
                 About = "About me", RequesterID = "FAKE", Major = "Biology", School = "RPI", EmailAddress = "*****@*****.**", FullName = "Glenn Ferrie",
                  Interests = "Software Developer", LastUpdated = DateTime.Now, PhoneNumber = "2125551212", PreferredContactMethod = "Email"
            };

            var helper = new StorageHelper();
            helper.AddRequesterSubmission(info.RequesterID, info);
        }
Пример #6
0
        public ActionResult SaveContactData(FormCollection collection)
        {
            #region Util function
            // utility function
            Func<FormCollection, string> __getInterests = c =>
            {
                return string.Join(",", posList.Where(q => c[q.OptionName] != null).Select(a => a.Value).ToArray<object>());
                // NOTE: casted as object array to eliminate method abiguity
            };
            #endregion

            var info = new ContactInfo();

            // scrape form data

            info.FullName = collection["name"];
            info.EmailAddress = collection["email"];
            info.PhoneNumber = collection["phone"];
            info.Major = collection["major"];
            info.About = collection["about"];
            info.PreferredContactMethod = collection["contact-pref"];
            info.Interests = __getInterests(collection);
            info.LastUpdated = DateTime.Now;
            info.RequesterID = collection["requesterid"];
            info.GradYear = collection["gradyear"];
            info.JobType = collection["jobtype"];

            if (Session["_ActiveSchool"] != null) {
                var data = (SchoolData)Session["_ActiveSchool"];
                info.School = data.Alias;
            }

            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];
                if (!string.IsNullOrWhiteSpace(file.FileName))
                {
                    info.UploadKey = string.Format("{0}-{1:yyyyMMddHHmmss}{2}", info.RequesterID, DateTime.Now, Path.GetExtension(file.FileName));
                    repo.SaveAttachment(info.UploadKey, file.InputStream);
                }
            }

            var mm = new MailManager();
            mm.NotifySave(info);

            // add cookies
            Response.Cookies[CookieNames.LastUpdated].Value = info.LastUpdated.ToString();
            Response.Cookies[CookieNames.FullName].Value = info.FullName;
            Response.Cookies[CookieNames.EmailAddress].Value = info.EmailAddress;
            Response.Cookies[CookieNames.Phone].Value = info.PhoneNumber;
            Response.Cookies[CookieNames.Major].Value = info.Major;
            Response.Cookies[CookieNames.About].Value = info.About;
            Response.Cookies[CookieNames.Interests].Value = info.Interests;
            Response.Cookies[CookieNames.PreferredContactMethod].Value = info.PreferredContactMethod;
            Response.Cookies[CookieNames.RequesterID].Value = info.RequesterID;
            Response.Cookies[CookieNames.GradYear].Value = info.GradYear;
            Response.Cookies[CookieNames.JobType].Value = info.JobType;

            CookieNames.SetResponseLifetime(Response, 365); // in days

            // save contact info
            repo.SaveContact(info);

            HttpContext.Cache.Add("Saved", true, null, DateTime.Now.AddSeconds(15), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);

            return RedirectToAction("Index");
        }
Пример #7
0
        // get saved data from cookies
        private void FillContactInfoFromCookies(ContactInfo info)
        {
            if (Request.Cookies[CookieNames.LastUpdated] != null && Session["DO_NOT_SAVE"] == null)
            {
                var nameCookie = Request.Cookies[CookieNames.FullName];
                var emailCookie = Request.Cookies[CookieNames.EmailAddress];
                var phoneCookie = Request.Cookies[CookieNames.Phone];
                var majorCookie = Request.Cookies[CookieNames.Major];
                var aboutCookie = Request.Cookies[CookieNames.About];
                var intsCookie = Request.Cookies[CookieNames.Interests];
                var pcmCookie = Request.Cookies[CookieNames.PreferredContactMethod];
                var ridCookie = Request.Cookies[CookieNames.RequesterID];
                var lastUpdatedCookie = Request.Cookies[CookieNames.LastUpdated];
                var gradYearCookie = Request.Cookies[CookieNames.GradYear];
                var jobTypeCookie = Request.Cookies[CookieNames.JobType];

                info.FullName = nameCookie == null ? string.Empty : nameCookie.Value;
                info.EmailAddress = emailCookie  == null ? string.Empty : emailCookie.Value;
                info.PhoneNumber = phoneCookie == null ? string.Empty : phoneCookie.Value;
                info.Major = majorCookie == null ? string.Empty : majorCookie.Value;
                info.About = aboutCookie == null ? string.Empty : aboutCookie.Value;
                info.Interests = intsCookie == null ? string.Empty : intsCookie.Value;
                info.PreferredContactMethod = pcmCookie == null ? string.Empty : pcmCookie.Value;
                info.RequesterID = ridCookie == null ? string.Empty : ridCookie.Value;
                info.GradYear = gradYearCookie == null ? string.Empty : gradYearCookie.Value;
                info.JobType = jobTypeCookie == null ? string.Empty : jobTypeCookie.Value;
                info.LastUpdated = lastUpdatedCookie == null ? null : new DateTime?(DateTime.Parse(lastUpdatedCookie.Value));

                if (string.IsNullOrWhiteSpace(info.RequesterID))
                    info.RequesterID = Guid.NewGuid().ToString();
            }
            else
            {
                info.RequesterID = Guid.NewGuid().ToString();
            }
        }
Пример #8
0
        public void AddRequesterSubmission(string requesterId, ContactInfo submission)
        {
            var dir = client.GetContainerReference("studentconnect-submissions");
            var submissions = dir.GetBlockBlobReference(requesterId);

            if (submissions.Exists())
            {
                var xml = submissions.DownloadText();
                var ser = new XmlSerializer(typeof(RequesterSubmissions));
                RequesterSubmissions rs;
                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml.ToCharArray())))
                {
                    rs = (RequesterSubmissions)ser.Deserialize(ms);
                    // submit
                    rs.Submissions.Add(submission);
                }

                using (var ms = new MemoryStream())
                {
                    ser.Serialize(ms, rs);
                    // submit
                    ms.Position = 0;
                    submissions.UploadFromStream(ms);
                }
            }
            else
            {
                // create empty element
                var rs = new RequesterSubmissions() { RequesterID = requesterId };
                // add data
                rs.Submissions.Add(submission);
                // serialize
                var ser = new XmlSerializer(typeof(RequesterSubmissions));
                using (var ms = new MemoryStream())
                {
                    ser.Serialize(ms, rs);
                    // submit
                    ms.Position = 0;
                    submissions.UploadFromStream(ms);
                }

            }
        }
Пример #9
0
 public void SaveContact(ContactInfo info)
 {
     store.AddRequesterSubmission(info.RequesterID, info);
 }