public async Task <OperatorRequestModel> GetById(int id)
        {
            OperatorRequestModel response;
            var account = await _accountService.GetById(id);

            if (account != null)
            {
                response = new OperatorRequestModel
                {
                    Id       = account.AccountId,
                    Fullname = account.FullName,
                    Username = account.Username,
                    Email    = account.Email,
                    Phone    = account.Phone,
                };
            }
            else
            {
                response = new OperatorRequestModel
                {
                };
            }

            return(response);
        }
        public async Task <ResponseViewModel> Update(int id, [FromBody] OperatorRequestModel model)
        {
            var oper = await _accountService.GetById(id);

            if (oper == null)
            {
                var response = new ResponseViewModel
                {
                    Result = false,
                };

                response.Messages.Add("Không tìm thấy tài khoản");

                return(response);
            }

            oper.FullName = model.Fullname;
            oper.Email    = model.Email;
            oper.Phone    = model.Phone;
            if (!string.IsNullOrEmpty(model.Password))
            {
                oper.Password = Encryptor.MD5Hash(model.Password);
            }
            return(await SaveOrUpdate(oper));
        }
Exemple #3
0
        public async Task <OperatorRequestModel> GetById(int id)
        {
            OperatorRequestModel response;
            var account = await _accountService.GetById(id);

            if (account != null)
            {
                response = new OperatorRequestModel
                {
                    Id                = account.AccountId,
                    Fullname          = account.FullName,
                    Username          = account.Username,
                    Email             = account.Email,
                    Phone             = account.Phone,
                    AccountTypeId     = account.AccountTypeId,
                    AccountStatusId   = account.AccountStatusId,
                    BranchId          = account.BranchId,
                    Address           = account.Address,
                    DateOfBirth       = account.DateOfBirth,
                    AccountStatusName = account.AccountStatus?.AccountStatusName,
                    AccountTypeName   = account.AccountType?.AccountTypeName,
                    BranchName        = account.Branch?.BranchName,
                };
            }
            else
            {
                response = new OperatorRequestModel
                {
                };
            }

            return(response);
        }
        public async Task <ResponseViewModel> Save([FromBody] OperatorRequestModel model)
        {
            var oldOperator = await _accountService.GetByUsername(model.Username);

            if (oldOperator != null)
            {
                var response = new ResponseViewModel
                {
                    Result = false,
                };

                response.Messages.Add("Tên tài khoản hoặc email đã tồn tại");

                return(response);
            }
            else
            {
                var account = new Account
                {
                    FullName = model.Fullname,
                    Username = model.Username,
                    Email    = model.Email,
                    Phone    = model.Phone,
                    //StatusId = model.StatusId,
                    Password = Encryptor.MD5Hash(model.Password),
                };
                return(await SaveOrUpdate(account));
            }
        }
Exemple #5
0
        public async Task <ResponseViewModel> Create([FromBody] OperatorRequestModel model)
        {
            var oldOperator = await _accountService.GetByUsername(model.Username);

            if (oldOperator != null)
            {
                var response = new ResponseViewModel
                {
                    Result = false,
                };

                response.Messages.Add("Tên tài khoản hoặc email đã tồn tại");

                return(response);
            }
            else
            {
                var account = new Account
                {
                    Username        = model.Username,
                    FullName        = model.Fullname,
                    Email           = model.Email,
                    Phone           = model.Phone,
                    Address         = model.Address,
                    DateOfBirth     = model.DateOfBirth,
                    AccountTypeId   = model.AccountTypeId,
                    AccountStatusId = model.AccountStatusId,
                    BranchId        = model.BranchId,
                    Password        = Encryptor.MD5Hash(model.Password),
                };

                ApplyUserCreateEntity(account);

                return(await SaveOrUpdate(account));
            }
        }