示例#1
0
        public async Task <IActionResult> Create([Bind("Guid,UserName,Password,Role,Email,CreateTime,UpdateTime")]
                                                 Account account)
        {
            if (ModelState.IsValid)
            {
                account.Guid       = Guid.NewGuid();
                account.CreateTime = DateTime.Now;
                account.UpdateTime = DateTime.Now;
                account.Role       = UserRole.Ordinary;
                context.Add(account);
                await context.SaveChangesAsync();

                var partyMember =
                    new PartyMember(new SeriaNumber().Seria(pMContext.PartyMembers.Count() + 1, Key.PMPre))
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                pMContext.Add(partyMember);
                await pMContext.SaveChangesAsync();

                var accountPartyMember =
                    new AccountPartyMember(account.UserName, partyMember.PartyMemberID)
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now
                };
                aPMContext.Add(accountPartyMember);
                await aPMContext.SaveChangesAsync();

                var partyCost =
                    new PartyCost(new SeriaNumber().Seria(pCContext.PartyCosts.Count() + 1, Key.PCPre),
                                  partyMember.PartyMemberID)
                {
                    Guid       = Guid.NewGuid(),
                    CreateTime = DateTime.Now,
                    UpdateTime = DateTime.Now,
                    State      = Verify.Unaudited
                };
                pCContext.Add(partyCost);
                await pCContext.SaveChangesAsync();

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

            return(View(account));
        }
示例#2
0
        public async Task <IActionResult> Delete(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var partyMember = await context.PartyMembers
                              .FirstOrDefaultAsync(o => o.Guid == id);

            if (partyMember == null)
            {
                return(NotFound());
            }
            var partyCost = await pCContext.PartyCosts
                            .FirstOrDefaultAsync(pC => pC.PartyMemberID == partyMember.PartyMemberID);

            var accountPartyMember = await aPMContext.AccountPartyMembers
                                     .FirstOrDefaultAsync(aPM => aPM.PartyMemberID == partyMember.PartyMemberID);

            if (accountPartyMember == null)
            {
                return(NotFound());
            }
            var account = await accContext.Accounts
                          .FirstOrDefaultAsync(aC => aC.UserName == accountPartyMember.AccountID);

            accContext.Accounts.Remove(account);
            aPMContext.AccountPartyMembers.Remove(accountPartyMember);
            pCContext.PartyCosts.Remove(partyCost);
            context.PartyMembers.Remove(partyMember);

            await accContext.SaveChangesAsync();

            await aPMContext.SaveChangesAsync();

            await pCContext.SaveChangesAsync();

            await context.SaveChangesAsync();

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