コード例 #1
0
        public async Task EditAsync(PersonModel model, string userId)
        {
            NRZ.Data.Person person = await _context.Person.Include(x => x.Address).FirstOrDefaultAsync(x => x.Id == model.Id && !x.Deleted);

            if (person != null)
            {
                person.ToUpdate(model);

                if (model.Address != null)
                {
                    if (model.Address.Id.HasValue)
                    {
                        await _addressService.EditAsync(model.Address);
                    }
                    else
                    {
                        person.Address = model.Address.ToAddress();
                    }
                }
                else
                {
                    person.AddressId = null;
                }

                if (model.UserId != null)
                {
                    var aspNetUser = _context.AspNetUsers.Where(x => x.Id == model.UserId).FirstOrDefault();
                    aspNetUser.Email           = model.Email;
                    aspNetUser.NormalizedEmail = model.Email.ToUpper();
                }

                SetUpdateStamp(person, userId);
                await _context.SaveChangesAsync();
            }
        }
コード例 #2
0
        public async Task DeleteAsync(int personId, string userId)
        {
            NRZ.Data.Person person = await _context.Person.FirstOrDefaultAsync(x => x.Id == personId && !x.Deleted);

            if (person != null)
            {
                SetDeleteStamp(person, userId);
                await _context.SaveChangesAsync();
            }
        }
コード例 #3
0
        public async Task CreateAsync(PersonModel model, string userId = null)
        {
            NRZ.Data.Person person = model.ToPerson();

            if (model.UserId != null)
            {
                var aspNetUser = _context.AspNetUsers.Where(x => x.Id == model.UserId).FirstOrDefault();
                aspNetUser.Email           = model.Email;
                aspNetUser.NormalizedEmail = model.Email.ToUpper();
            }
            SetCreateStamp(person, userId);

            await _context.Person.AddAsync(person);

            await _context.SaveChangesAsync();
        }