public async Task <ZhivarUserInfo2> GetUserInfoAsync(int?id, string userName) { using (var uow = this.UnitOfWork) { UserInfo userInfo; if (id != null) { userInfo = await this.Queryable().Where(u => u.ID == id).FirstOrDefaultAsync(); } else { userInfo = await this.Queryable().Where(u => u.UserName == userName).FirstOrDefaultAsync(); } if (userInfo == null) { throw new BusinessException($"کاربر وجود ندارد", null, 13); } UserInfo user = userInfo.Translate <UserInfo>(); //Shakhs shakhs = await this.UnitOfWork.RepositoryAsync<Shakhs>() // .Queryable() // .Where(sh => sh.ID == user.ShakhsId) // .FirstOrDefaultAsync(); ZhivarUserInfo2 userData = new ZhivarUserInfo2() { CodeMeli = user.NationalCode, Email = user.Email, UserName = user.UserName, Jensiat = user.Gender, ID = user.ID, //MarkazDarmaniId = user.MarkazDarmaniId, Mobile = user.MobileNo, Nam = user.FirstName, NameKhanevadegi = user.LastName, //NoeKarbar = EnumHelper.GetEnum<ZhivarEnums.ZhivarUserType>(user.AuthenticationType), // ShakhsId = user.ShakhsId, // TarikheTavallod = shakhs != null ? shakhs.TarikheTavallod : null, Tel = user.Tel, }; return(userData); } }
public void UpdateUserAsync(int?userId, ZhivarUserInfo2 user) { var userInfo = this.FindEntity(userId); if (userInfo == null) { throw new BusinessException($"کاربر وجود ندارد", null, 13); } userInfo.Email = user.Email != null ? user.Email : userInfo.Email; userInfo.FirstName = !string.IsNullOrEmpty(user.Nam) ? user.Nam : userInfo.FirstName; userInfo.Gender = user.Jensiat != null ? user.Jensiat : userInfo.Gender; userInfo.LastName = !string.IsNullOrEmpty(user.NameKhanevadegi) ? user.NameKhanevadegi : userInfo.LastName; //userInfo.MobileNo = user.Mobile; userInfo.NationalCode = !string.IsNullOrEmpty(user.CodeMeli) ? user.CodeMeli : userInfo.NationalCode; //userInfo.Password = user.Password; //userInfo.PlainPassword = user.PlainPassword; userInfo.Tel = !string.IsNullOrEmpty(user.Tel) ? user.Tel : userInfo.Tel; this.Repository.Update(userInfo); this.SaveChanges(); //Shakhs shakhs = BusinessContext.GetBusinessRule<Shakhs>(this.OperationAccess, this.UnitOfWork) // .Queryable() // .Where(sh => sh.ID == userInfo.ShakhsId) // .FirstOrDefault(); //if (shakhs == null) // shakhs = new Shakhs(); //shakhs.CodeMeli = !string.IsNullOrEmpty(user.CodeMeli) ? user.CodeMeli : shakhs.CodeMeli; //shakhs.Jensiat = user.Jensiat != null ? EnumHelper.GetEnum<ZhivarEnums.Jensiat>(Convert.ToInt32(user.Jensiat)) : shakhs.Jensiat; //shakhs.Mobile = !string.IsNullOrEmpty(user.Mobile) ? user.Mobile : shakhs.Mobile; //shakhs.Nam = !string.IsNullOrEmpty(user.Nam) ? user.Nam : shakhs.Nam; //shakhs.NameKhanevadegi = !string.IsNullOrEmpty(user.NameKhanevadegi) ? user.NameKhanevadegi : shakhs.NameKhanevadegi; //shakhs.TarikheTavallod = user.TarikheTavallod != null ? user.TarikheTavallod : shakhs.TarikheTavallod; //using (UnitOfWork uow = new OMF.EntityFramework.Ef6.UnitOfWork()) //{ // var shakhsRep = uow.Repository<Shakhs>(); // shakhsRep.InsertOrUpdateGraph(shakhs); // uow.SaveChanges(); //} }