Ejemplo n.º 1
0
        public ActionResult ImportCalendar(HttpPostedFileBase calendarfile)
        {
            try
            {
                if (calendarfile != null && calendarfile.ContentLength > 0)
                {
                    var calendars   = iCalendar.LoadFromStream(calendarfile.InputStream);
                    var occurrences = calendars.GetOccurrences(new iCalDateTime(DateTime.Now.Year, 1, 1),
                                                               new iCalDateTime(2020, 12, 31));
                    if (occurrences.Count == 0)
                    {
                        return(RedirectToAction("Index").Warning("0 records were imported. Please double check your file and try again."));
                    }

                    foreach (var occurrence in occurrences)
                    {
                        var rc = occurrence.Source as IRecurringComponent;
                        if (rc != null)
                        {
                            var user = GetUser();
                            if (user != null)
                            {
                                var existingEvent = user.CalendarEvents.SingleOrDefault(c => c.CalendarEventDate == occurrence.Period.StartTime.Local && c.Name == rc.Summary);

                                if (existingEvent == null)
                                {
                                    user.CalendarEvents.Add(new CalendarEvent {
                                        CalendarEventDate = occurrence.Period.StartTime.Local, Name = rc.Summary
                                    });
                                }
                            }

                            _context.SaveChanges();
                        }
                    }
                }
                return(RedirectToAction("Index").Success("Your calendar was successfully imported!"));
            }
            catch (Exception x)
            {
                return(RedirectToAction("Index").Error("The following error occurred " + x.Message));
            }
        }
Ejemplo n.º 2
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (var db = new HowManyDaysTilContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }