コード例 #1
0
        public async Task <IActionResult> PutProducts(int id, Products products)
        {
            if (id != products.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Gender,RegisteredDate,SelectedEvents,AdditionalRequest,Events")] UserViewModel users)
        {
            for (int i = 0; i < users.Events.Count(); i++)
            {
                if (users.Events[i].IsSelected)
                {
                    if (users.SelectedEvents != null)
                    {
                        users.SelectedEvents += "," + users.Events[i].EventName;
                    }
                    else
                    {
                        users.SelectedEvents += users.Events[i].EventName;
                    }

                    ModelState.Remove("SelectedEvents");
                }
            }

            if (ModelState.IsValid)
            {
                Users usr = new Users()
                {
                    Email             = users.Email,
                    Name              = users.Name,
                    Gender            = users.Gender,
                    RegisteredDate    = users.RegisteredDate,
                    SelectedEvents    = users.SelectedEvents,
                    AdditionalRequest = users.AdditionalRequest,
                    Id = Guid.NewGuid()
                };

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

                return(RedirectToAction(nameof(Index)));
            }

            users.Events = new List <EventViewModel>
            {
                new EventViewModel {
                    EventName = "Day 1", IsSelected = false
                },
                new EventViewModel {
                    EventName = "Day 2", IsSelected = false
                },
                new EventViewModel {
                    EventName = "Day 3", IsSelected = false
                }
            };


            return(View(users));
        }