public async Task <IActionResult> PutMoodType([FromRoute] int id, [FromBody] MoodType moodType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != moodType.MoodTypeID)
            {
                return(BadRequest());
            }

            _context.Entry(moodType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MoodTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Name,ID,Date,Day,Symptoms, Body")] JournalModel journal)
        {
            if (ModelState.IsValid)
            {
                _context.Add(journal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(journal));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Author,IsPrivate")] Coach coach)
        {
            if (ModelState.IsValid)
            {
                _context.Add(coach);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(coach));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("Id,DateTime,Document")] Conversation conversation)
        {
            if (ModelState.IsValid)
            {
                _context.Add(conversation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(conversation));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName")] User user)
        {
            if (ModelState.IsValid)
            {
                //user.Id = Guid.NewGuid();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("JournalID,JournalText")] Journal journal)
        {
            if (ModelState.IsValid)
            {
                journal.JournalUser     = User.Identity.Name;
                journal.JournalDateTime = DateTime.Now;
                _context.Add(journal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(journal));
        }
 public async Task <Activity> CreateActivity(Activity activity)
 {
     using (var context = new JournalContext())
     {
         context.Activity.Add(activity);
         return(await context.SaveChangesAsync());
     }
 }
示例#8
0
        public async Task <Guid> CreateAsync(JournalData journal)
        {
            await _context.AddAsync(journal);

            await _context.SaveChangesAsync();

            return(journal.Id);
        }
示例#9
0
        //
        // GET: /ShoppingCart/AddToCart/5

        public async Task <IActionResult> AddToCart(Guid id, CancellationToken requestAborted)
        {
            // Retrieve the joiurnal from the database
            var journal = await _context.Journals
                          .SingleAsync(x => x.JournalId == id, cancellationToken : requestAborted);

            // Add it to the shopping cart
            var cart = Cart.GetCart(_context, HttpContext);

            await cart.AddToCart(journal);

            await _context.SaveChangesAsync(requestAborted);

            _logger.LogInformation("Journal {journalId} was added to the cart.", journal.JournalId);

            // Go back to the main store page for more shopping
            return(RedirectToAction("Index"));
        }
示例#10
0
        public async Task <ActionResult <ToDoItems> > AddToDoItems(ToDoItems item, DateTime date)
        {
            item.toBeCompletedBy = date;
            _context.TodoItems.Add(item);
            await _context.SaveChangesAsync();

            // return CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item);
            return(item);
        }
示例#11
0
        public async Task <IActionResult> Create(
            Journal journal,
            [FromServices] IMemoryCache cache,
            CancellationToken requestAborted)
        {
            if (ModelState.IsValid)
            {
                _context.Journals.Add(journal);
                await _context.SaveChangesAsync(requestAborted);

                var journalData = new Journal
                {
                    Title    = journal.Title,
                    ImageUrl = Url.Action("Details", "Store", new { id = journal.JournalId })
                };

                cache.Remove("latestJournal");
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId  = new SelectList(_context.Categories, "CategoryId", "Name", journal.CategoryId);
            ViewBag.PublisherId = new SelectList(_context.Publishers, "PublisherId", "Name", journal.Publisher.PublisherId);
            return(View(journal));
        }
示例#12
0
        public async Task <IActionResult> AddressAndPayment(
            [FromServices] JournalContext context,
            [FromForm] Subscription subscription,
            CancellationToken requestAborted)
        {
            if (!ModelState.IsValid)
            {
                return(View(subscription));
            }

            var formCollection = await HttpContext.Request.ReadFormAsync();

            try
            {
                if (string.Equals(formCollection["PromoCode"].FirstOrDefault(), PromoCode,
                                  StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(subscription));
                }
                else
                {
                    subscription.User.UserName = HttpContext.User.Identity.Name;
                    subscription.Created       = DateTime.UtcNow;

                    //Add the Order
                    context.Subscriptions.Add(subscription);

                    //Process the order
                    var cart = Cart.GetCart(context, HttpContext);
                    await cart.CreateSubscription(subscription);

                    _logger.LogInformation("User {userName} started checkout of {orderId}.", subscription.User.UserName, subscription.SubscriptionId);

                    // Save all changes
                    await context.SaveChangesAsync(requestAborted);

                    return(RedirectToAction("Complete", new { id = subscription.SubscriptionId }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(subscription));
            }
        }
 public async Task AddAsync(JournalOwner journalOwner)
 {
     m_context.JournalOwners.Add(journalOwner);
     await m_context.SaveChangesAsync();
 }
 public async Task AddAsync(JournalEntry journalEntry)
 {
     m_context.JournalEntries.Add(journalEntry);
     await m_context.SaveChangesAsync();
 }
示例#15
0
        public GcItem Get([FromQuery] string value, [FromQuery] string coach, [FromQuery] int index)
        {
            //get coach
            GcItem output = new GcItem();

            //update convo
            Conversation convo = null;
            Coach        c     = null;

            if (HttpContext.Session.IsAvailable && HttpContext.Session.Keys.Contains("convo-" + coach))
            {
                string convoId = HttpContext.Session.GetString("convo-" + coach);
                if (convoId != null)
                {
                    convo = _context.Conversations
                            .Include(i => i.QuestionsAsked)
                            .Include(i => i.ResponseList)
                            .Include(i => i.Coach)
                            .ThenInclude(coachItem => coachItem.QuestionList)

                            .OrderByDescending(e => e.DateTime)
                            .Where(i => i.SessionTag == convoId).SingleOrDefault();
                    convo.ResponseList.Add(new Response
                    {
                        Index          = index,
                        IsTextResponse = true,
                        TextResponse   = value
                    });

                    c = convo.Coach;
                }
            }
            else
            {
                //no convo...request client to send data
                return(new GcItem {
                    Content = "Thats all I have today, ive safely saved your journal entries.", Author = "Coach " + c.Name, compstyle = "coach", Type = "Final"
                });
            }


            if (index >= c.QuestionList.Count)
            {
                //submit
                convo.QuestionsAsked.Add(new Question
                {
                    Index        = index + 1,
                    QuestionText = "Thats all I have today, come back tomorrow",
                    Type         = QuestionType.Text
                });
                convo.inProgress = false;
                _context.SaveChangesAsync();

                return(new GcItem {
                    Content = "Thats all I have today, ive safely saved your journal entries.", Author = "Coach " + c.Name, compstyle = "coach", Type = "Final"
                });
            }
            else
            {
                Question nextQ = c.QuestionList[index];

                convo.QuestionsAsked.Add(new Question
                {
                    Index        = index + 1,
                    QuestionText = nextQ.QuestionText,
                    Type         = nextQ.Type
                });
                _context.SaveChangesAsync();

                return(new GcItem {
                    Content = nextQ.QuestionText, Author = "Coach " + c.Name, compstyle = "coach", Type = nextQ.Type.ToString()
                });
            }
        }