示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Code,Address")] HomeCodes homeCodes)
        {
            if (id != homeCodes.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(homeCodes);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HomeCodesExists(homeCodes.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(homeCodes));
        }
        public async Task <ActionResult <MobileUsers> > PostMobileUsers(MobileUsers mobileUsers)
        {
            var user = await _context.MobileUsers.Where(m => (m.FName == mobileUsers.FName) && (m.Lname == mobileUsers.Lname) && (m.Code == mobileUsers.Code) && (m.date == mobileUsers.date)).ToListAsync();

            var homeCode = await _context.HomeCodes.Where(m => m.Code == mobileUsers.Code).ToListAsync();

            //Only register a user if they use a valid, pre-exisiting home code
            if (homeCode.Count() != 0 && user.Count() == 0)
            {
                HomeCodes hc = homeCode.Find(m => m.Code == mobileUsers.Code);
                mobileUsers.address = hc.Address;
                _context.MobileUsers.Add(mobileUsers);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetMobileUsers", new { id = mobileUsers.Id }, mobileUsers));
            }
            else if (homeCode.Count() != 0 && user.Count() != 0)
            {
                //User is already created, send back a message stating so
                mobileUsers.Id = -1;
                return(CreatedAtAction("GetMobileUsers", new { id = "-1" }, mobileUsers));
            }
            else
            {
                return(NotFound());
            }
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,Code,Address")] HomeCodes homeCodes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(homeCodes);
                await _context.SaveChangesAsync();

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