Beispiel #1
0
        public async Task <Student> Save(Student value, StudentRelationShip valueRelationShip, IEnumerable <StudentBecome> becomes, Guid?index)
        {
            value.BranchId = value.CreatedBy.GetBranchOfCurrentUser(this.appContext);
            var itemExist = await Get(index);

            if (itemExist == null)
            {
                var result = await appContext.Student.AddAsync(value);

                await appContext.StudentRelationShip.AddAsync(valueRelationShip);

                await appContext.SaveChangesAsync();

                return(result.Entity);
            }
            else
            {
                itemExist.StudentCode = value.StudentCode;

                itemExist.StudentName = value.StudentName;
                itemExist.AccountBank = value.AccountBank;
                itemExist.Address     = value.Address;
                itemExist.Birthday    = value.Birthday;
                itemExist.ClassName   = value.ClassName;
                itemExist.SchoolName  = value.SchoolName;
                itemExist.Phone       = value.Phone;
                itemExist.TaxCode     = value.TaxCode;
                itemExist.Email       = value.Email;
                itemExist.GenderId    = value.GenderId;
                itemExist.UserName    = value.UserName;
                itemExist.Password    = value.Password;
                itemExist.Note        = value.Note;

                var itemRelation = await FindRelationShipByStudentId(itemExist.StudentId);

                if (itemRelation == null)
                {
                    await appContext.StudentRelationShip.AddAsync(valueRelationShip);
                }
                else
                {
                    itemRelation.StudentId       = itemExist.StudentId;
                    itemRelation.FullName        = valueRelationShip.FullName;
                    itemRelation.Facebook        = valueRelationShip.Facebook;
                    itemRelation.Address         = valueRelationShip.Address;
                    itemRelation.Email           = valueRelationShip.Email;
                    itemRelation.Job             = valueRelationShip.Job;
                    itemRelation.Phone           = valueRelationShip.Phone;
                    itemRelation.Birthday        = value.Birthday;
                    itemRelation.BranchId        = Guid.NewGuid();
                    itemRelation.RelationRequire = valueRelationShip.RelationRequire;
                    itemRelation.CreatedDate     = DateTime.Now;
                    itemRelation.UpdatedDate     = DateTime.Now;

                    itemRelation.UpdatedBy = valueRelationShip.UpdatedBy;
                }

                // becomes
                foreach (var item in becomes)
                {
                    var itemB = this.appContext.StudentBecome.FirstOrDefault(p => p.StudentBecomeDesId == item.StudentBecomeDesId && p.StudentId == item.StudentId);
                    if (itemB != null)
                    {
                        itemB.IsDeleted = !item.IsExist;
                        itemB.Note      = $"{!item.IsExist}";
                    }
                    else
                    {
                        item.IsDeleted = !item.IsExist;
                        await this.appContext.StudentBecome.AddAsync(item);
                    }
                }

                await appContext.SaveChangesAsync();

                return(itemExist);
            }
        }
Beispiel #2
0
        public async Task <Student> Save(Student value, StudentRelationShip valueRelationShip, Guid?index)
        {
            value.BranchId = value.CreatedBy.GetBranchOfCurrentUser(this.appContext);
            var itemExist = await Get(index);

            if (itemExist == null)
            {
                var result = await appContext.Student.AddAsync(value);

                await appContext.StudentRelationShip.AddAsync(valueRelationShip);

                await appContext.SaveChangesAsync();

                return(result.Entity);
            }
            else
            {
                itemExist.StudentCode = value.StudentCode;

                itemExist.StudentName = value.StudentName;
                itemExist.AccountBank = value.AccountBank;
                itemExist.Address     = value.Address;
                itemExist.Birthday    = value.Birthday;
                itemExist.ClassName   = value.ClassName;
                itemExist.SchoolName  = value.SchoolName;
                itemExist.Phone       = value.Phone;
                itemExist.TaxCode     = value.TaxCode;
                itemExist.Email       = value.Email;
                itemExist.GenderId    = value.GenderId;
                itemExist.UserName    = value.UserName;
                itemExist.Password    = value.Password;
                itemExist.Note        = value.Note;

                var itemRelation = await FindRelationShipByStudentId(itemExist.StudentId);

                if (itemRelation == null)
                {
                    await appContext.StudentRelationShip.AddAsync(valueRelationShip);
                }
                else
                {
                    itemRelation.StudentId       = itemExist.StudentId;
                    itemRelation.FullName        = valueRelationShip.FullName;
                    itemRelation.Facebook        = valueRelationShip.Facebook;
                    itemRelation.Address         = valueRelationShip.Address;
                    itemRelation.Email           = valueRelationShip.Email;
                    itemRelation.Job             = valueRelationShip.Job;
                    itemRelation.Phone           = valueRelationShip.Phone;
                    itemRelation.Birthday        = value.Birthday;
                    itemRelation.BranchId        = Guid.NewGuid();
                    itemRelation.RelationRequire = valueRelationShip.RelationRequire;
                    itemRelation.CreatedDate     = DateTime.Now;
                    itemRelation.UpdatedDate     = DateTime.Now;

                    itemRelation.UpdatedBy = valueRelationShip.UpdatedBy;
                }

                await appContext.SaveChangesAsync();

                return(itemExist);
            }
        }