示例#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);
        }
示例#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;
        }
示例#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;
        }
示例#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;
        }
示例#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);
        }
示例#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;
        }
示例#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;
        }
示例#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);
        }