Example #1
0
        public void TestEditBatchNotes()
        {
            UserProfile jon = TestUtils.createUser(111, "Jon", "Smith");
            Batch batch = TestUtils.createBatch("Test", BatchType.Beer, jon);
            BatchNote note = TestUtils.createBatchNote(batch, "Test Note", "I am a note!", jon);

            BrewersBuddyContext db = new BrewersBuddyContext();

            var id = note.NoteId;
            var note1 = db.BatchNotes.Find(id);

            Assert.IsTrue(batch.Notes.Contains(note));
            Assert.AreEqual("Test Note", note1.Title);
            Assert.AreEqual("I am a note!", note1.Text);

            note.Title = "Test Title";

            // save changes
            db = new BrewersBuddyContext();
            db.Entry(note).State = System.Data.EntityState.Modified;
            db.SaveChanges();

            //clear context and reload
            db = new BrewersBuddyContext();
            note1 = db.BatchNotes.Find(id);

            // verify local context is not being used
            note.Text = "test text";

            Assert.AreEqual("Test Title", note1.Title);
            Assert.AreEqual("I am a note!", note1.Text);
        }
Example #2
0
        public static BatchComment createBatchComment(Batch batch, UserProfile user, string comment)
        {
            BrewersBuddyContext db = new BrewersBuddyContext();

            BatchComment batchComment = new BatchComment();
            batchComment.Batch = batch;
            batchComment.User = user;
            batchComment.Comment = comment;

            db.BatchComments.Add(batchComment);

            db.SaveChanges();

            return batchComment;
        }
Example #3
0
        public static BatchRating createBatchRating(Batch batch, UserProfile user, int rating, string comment)
        {
            BrewersBuddyContext db = new BrewersBuddyContext();

            BatchRating batchRating = new BatchRating();
            batchRating.Batch = batch;
            batchRating.User = user;
            batchRating.Rating = rating;
            batchRating.Comment = comment;

            db.BatchRatings.Add(batchRating);

            db.SaveChanges();

            return batchRating;
        }
Example #4
0
        public static BatchNote createBatchNote(Batch batch, String title, String text, UserProfile user)
        {
            BrewersBuddyContext db = new BrewersBuddyContext();

            BatchNote note = new BatchNote();
            note.Batch = batch;
            note.Text = text;
            note.Title = title;
            note.AuthorId = user.UserId;
            note.AuthorDate = DateTime.Now;

            db.BatchNotes.Add(note);
            db.SaveChanges();

            return note;
        }
Example #5
0
        public static Batch createBatch(String name, BatchType type, UserProfile owner)
        {
            BrewersBuddyContext db = new BrewersBuddyContext();

            Batch batch = new Batch();
            batch.Name = name;
            batch.Type = type;
            batch.OwnerId = owner.UserId;
            batch.StartDate = DateTime.Now;

            db.Batches.Add(batch);

            db.SaveChanges();

            return batch;
        }
        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 (BrewersBuddyContext db = new BrewersBuddyContext())
                {
                    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);
        }
Example #7
0
        public static Measurement createMeasurement(Batch batch, String name, String description, String measured, Double value)
        {
            BrewersBuddyContext db = new BrewersBuddyContext();

            Measurement measurment = new Measurement();
            measurment.Batch = batch;
            measurment.Name = name;
            measurment.Description = description;
            measurment.Measured = measured;
            measurment.MeasurementDate = DateTime.Now;
            measurment.Value = value;

            db.Measurements.Add(measurment);
            db.SaveChanges();

            return measurment;
        }
Example #8
0
        public static UserProfile createUser(int userId, String firstName, String lastName)
        {
            BrewersBuddyContext db = new BrewersBuddyContext();

            UserProfile user = new UserProfile();
            user.UserId = userId;
            user.FirstName = firstName;
            user.LastName = lastName;

            //TODO should we register them somehow??
            db.UserProfiles.Add(user);
            db.SaveChanges();

            return user;
        }
Example #9
0
        public ActionResult EditNote(BatchNote note)
        {
            if (ModelState.IsValid)
            {
                BrewersBuddyContext db2 = new BrewersBuddyContext();
                db2.Entry(note).State = EntityState.Modified;
                db2.SaveChanges();

                //Associate the batch with the note
                int batchId = (int)Session["CurrentBatchId"];

                return RedirectToAction("Details/" + batchId);
            }
            return View(note);
        }