Пример #1
0
        public ActionResult DeleteQuestion(Guid id)
        {
            var context  = new StackOverflowContext();
            var question = context.Questions.Find(id);

            var answers = context.Answers.Include(r => r.QuestionReference);

            foreach (Answer ans in answers)
            {
                if (ans.QuestionReference.Id == id)
                {
                    context.Answers.Remove(ans);
                }
            }

            context.Questions.Remove(question);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public Bookmark CreateBookmark(int profileId, int postId, string note)
        {
            using var db = new StackOverflowContext();
            Bookmark bookmark = new Bookmark();

            bookmark.BookmarkId = NextBookmarkId(db);
            bookmark.ProfileId  = profileId;
            bookmark.PostId     = postId;
            bookmark.Note       = note;

            try
            {
                db.Bookmarks.Add(bookmark);
                db.SaveChanges();
                return(bookmark);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Пример #3
0
        public Profile CreateProfile(string email, string salt, string hash)
        {
            using var db = new StackOverflowContext();
            var profile = new Profile();

            profile.ProfileId = NextProfileId(db);
            profile.Email     = email;
            profile.Salt      = salt;
            profile.Hash      = hash;

            try
            {
                db.Profiles.Add(profile);
                db.SaveChanges();
                return(profile);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Пример #4
0
        public Query CreateQuery(int profileId, string queryText)
        {
            using var db = new StackOverflowContext();
            Query query = new Query();

            query.QueryId      = NextQueryId(db);
            query.ProfileId    = profileId;
            query.TimeSearched = DateTime.Now;
            query.QueryText    = queryText;

            try
            {
                db.Queries.Add(query);
                db.SaveChanges();
                return(query);
            }
            catch
            {
                return(null);
            }
        }
Пример #5
0
 public ActionResult IndexAddQuestion(AddNewQuestionModel model)
 {
     if (ModelState.IsValid)
     {
         var        context     = new StackOverflowContext();
         var        newQuestion = _mappingEngine.Map <AddNewQuestionModel, Question>(model);
         HttpCookie cookie      = Request.Cookies[FormsAuthentication.FormsCookieName];
         if (cookie != null)
         {
             FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
             Guid ownerId = Guid.Parse(ticket.Name);
             newQuestion.Votes            = 0;
             newQuestion.Owner            = context.Accounts.FirstOrDefault(x => x.Id == ownerId);
             newQuestion.ModificationDate = DateTime.Now;
             newQuestion.CreationDate     = DateTime.Now;
             context.Questions.Add(newQuestion);
             context.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Пример #6
0
        public ActionResult Register(AccountRegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var context = new StackOverflowContext();
                var account = context.Accounts.FirstOrDefault(x => x.Email == model.Email);
                if (account != null)
                {
                    model.ErrorMessage = "Email Already Used";
                    return(View(model));
                }
                account                = _mappingEngine.Map <AccountRegisterModel, Account>(model);
                account.Name          += (" " + model.Surname);
                account.CreationDate   = DateTime.Now;
                account.LastLogDate    = DateTime.Now;
                account.ViewsToProfile = 0;
                account.IsVerified     = false;
                context.Accounts.Add(account);
                context.SaveChanges();

                string host = Request.Url.GetLeftPart(UriPartial.Authority);
                string message;
                if (host.Contains("localhost:"))
                {
                    message = "Click to Confirm: " + host + "/Account/ConfirmRegister?id=" + account.Id;
                }
                else
                {
                    message = "Click to Confirm: " + "http://stackop4.apphb.com/Account/ConfirmRegister?id=" + account.Id;
                }
                new MailService().SendMail(model.Email, message);

                return(RedirectToAction("Login", new AccountLoginModel()));
            }
            return(View(model));
        }
Пример #7
0
 public void Add(TEntity obj)
 {
     _context.Set <TEntity>().Add(obj);
     _context.SaveChanges();
 }
Пример #8
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
Пример #9
0
 public void Incluir(TClass obj)
 {
     db.Set <TClass>().Add(obj);
     db.SaveChanges();
 }