コード例 #1
0
        public async Task <IActionResult> PutTripPackges(int id, TripPackges tripPackges)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;                // Calling User Data From Users Controller
            var Myusername     = claimsIdentity.FindFirst(ClaimTypes.Surname)?.Value; // Finding Current User

            if (id != tripPackges.TripPackgesId)
            {
                return(BadRequest());
            }
            tripPackges.TripPackgesId  = id;
            tripPackges.ModifiedUserId = int.Parse(User.Identity.Name); // Auto Update
            tripPackges.ModifiedBy     = Myusername;                    // Auto Update
            tripPackges.ModifiedDate   = DateTime.Now;

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <TripPackges> > PostTripPackges(TripPackges tripPackges)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;
            var Myusername     = claimsIdentity.FindFirst(ClaimTypes.Surname)?.Value;

            tripPackges.UserId      = int.Parse(User.Identity.Name);
            tripPackges.CreatedBy   = Myusername;
            tripPackges.CreatedDate = DateTime.Now;
            _context.TripPackgess.Add(tripPackges);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTripPackges", new { id = tripPackges.TripPackgesId }, tripPackges));
        }