コード例 #1
0
        public async Task <IActionResult> Create([Bind("id,StartTime,EndTime,Content,Point,Status,AspNetUserId,FeastId")] RegistrationFeast registrationFeast)
        {
            if (ModelState.IsValid)
            {
                ClaimsPrincipal currentUser   = this.User;
                var             currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
                registrationFeast.AspNetUserId = currentUserID;

                _context.Add(registrationFeast);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AspNetUserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", registrationFeast.AspNetUserId);
            ViewData["FeastId"]      = new SelectList(_context.Feasts, "id", "id", registrationFeast.FeastId);
            if (CurrentFeast.RediarectUrl != null)
            {
                string         messege  = "\"Feast.Content\": \"" + CurrentFeast.Content + "\",\n\"User\": \"" + registrationFeast.AspNetUser + "\",\n\"Content\": \"" + registrationFeast.Content + "\",\n\"StartTime\": \"" + registrationFeast.StartTime + "\",\n\"EndTime\": \"" + registrationFeast.EndTime + "\",\n\"Point\": \"" + registrationFeast.Point;
                HttpWebRequest request  = null;
                Uri            uri      = new Uri(CurrentFeast.RediarectUrl);
                UTF8Encoding   encoding = new UTF8Encoding();
                byte[]         bytes    = encoding.GetBytes(messege);
                request                       = (HttpWebRequest)WebRequest.Create(uri);
                request.Method                = "POST";
                request.ContentType           = "application/json";//"application/x-www-form-urlencoded";
                request.ContentLength         = bytes.Length;
                request.UseDefaultCredentials = true;
                using (Stream writeStream = request.GetRequestStream())
                {
                    writeStream.Write(bytes, 0, bytes.Length);
                }
            }
            return(View(registrationFeast));
        }
コード例 #2
0
        //        [Authorize(Roles = "admin")]
        public async Task <IActionResult> Edit(int id, [Bind("id,StartTime,EndTime,Content,Point,Status,AspNetUserId,FeastId")] RegistrationFeast registrationFeast)
        {
            if (id != registrationFeast.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(registrationFeast);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RegistrationFeastExists(registrationFeast.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AspNetUserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", registrationFeast.AspNetUserId);
            ViewData["FeastId"]      = new SelectList(_context.Feasts, "id", "id", registrationFeast.FeastId);
            return(View(registrationFeast));
        }