// public async Task<IActionResult> OnPostAsync(int id)
        public async Task <IActionResult> OnPostAsync(string id)
        {
            var personToUpdate = await _context.PersonalUserInfo.FindAsync(id);

            if (personToUpdate == null)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync <Person>(
                    personToUpdate,
                    "person",
                    s => s.Username, s => s.Name, s => s.Gender, s => s.IdentityCardNumber,
                    s => s.Status, s => s.PhoneNumber, s => s.Email, s => s.Password,
                    s => s.Address, s => s.HealthStatus, s => s.HealthCode, s => s.Visitedplaces,
                    s => s.PaymentInformation, s => s.PersonalCenterLink))
            {
                personToUpdate.UpdateTime = DateTime.Now;
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            return(Page());
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            #region snippet_TryUpdateModelAsync
            var emptyPerson = new Person();

            if (await TryUpdateModelAsync <Person>(
                    emptyPerson,
                    "person", // Prefix for form value.
                    s => s.Username, s => s.Name, s => s.Gender, s => s.IdentityCardNumber,
                    s => s.Status, s => s.PhoneNumber, s => s.Email, s => s.Password,
                    s => s.Address, s => s.HealthStatus, s => s.HealthCode, s => s.Visitedplaces,
                    s => s.PaymentInformation, s => s.PersonalCenterLink))
            {
                emptyPerson.Password     = BCrypt.Net.BCrypt.HashPassword(emptyPerson.Password);
                emptyPerson.CreationTime = DateTime.Now;
                emptyPerson.UpdateTime   = DateTime.Now;
                _context.PersonalUserInfo.Add(emptyPerson);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            #endregion

            return(Page());
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            #region snippet_TryUpdateModelAsync
            var emptyMerchant = new Merchant();

            if (await TryUpdateModelAsync <Merchant>(
                    emptyMerchant,
                    "merchant", // Prefix for form value.
                    s => s.Username, s => s.Password, s => s.Name, s => s.Address,
                    s => s.BusinessLicense, s => s.CorporateIdentity, s => s.Category,
                    s => s.PhoneNumber, s => s.Email, s => s.CollectionInformation))
            {
                emptyMerchant.Password = BCrypt.Net.BCrypt.HashPassword(emptyMerchant.Password);
                _context.MerchantUserInfo.Add(emptyMerchant);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            #endregion

            return(Page());
        }
Example #4
0
        // public async Task<IActionResult> OnPostAsync(int id)
        public async Task <IActionResult> OnPostAsync(string id)
        {
            var merchantToUpdate = await _context.MerchantUserInfo.FindAsync(id);

            if (merchantToUpdate == null)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync <Merchant>(
                    merchantToUpdate,
                    "merchant",
                    s => s.Username, s => s.Password, s => s.Name, s => s.Address,
                    s => s.BusinessLicense, s => s.CorporateIdentity, s => s.Category,
                    s => s.PhoneNumber, s => s.Email, s => s.CollectionInformation))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            return(Page());
        }