Esempio n. 1
0
        //[Authorize]
        public async Task <HttpResponseMessage> EditCustomer(CustomerProfileDetail customer)
        {
            var messageData = CreateMessageData($"customer");

            if (!ModelState.IsValid)
            {
                return(CreateValidationErrorResponse(messageData, new ValidationResult(Validation.InvalidParameters)));
            }
            var result = await _customerService.EditCustomer(customer);

            if (!result.IsSuccess)
            {
                return(CreateValidationErrorResponse(messageData, new ValidationResult(result.message)));
            }
            return(CreateOkResponse(messageData, customer));
        }
Esempio n. 2
0
        public async Task <LogicResult <CustomerProfileDetail> > GetCustomerProfile(int id)
        {
            if (id <= 0)
            {
                return new LogicResult <CustomerProfileDetail>()
                       {
                           IsSuccess = false, message = Validation.InvalidParameters
                       }
            }
            ;
            else
            {
                var unitofwork = _repositoryHelper.GetUnitOfWork();

                var repo      = _repositoryHelper.GetRepository <ICustomerRepository>(unitofwork);
                var custommer = await repo.GetByIdAsync(id);

                var result = new CustomerProfileDetail()
                {
                    ID     = custommer.ID,
                    Gender = custommer.Gender,
                    DoB    = custommer.DoB,
                    //Age = DateTime.Now.Year - custommer.DoB.Value.Year,
                    Profession = custommer.Profression,
                    PassWord   = custommer.passWord,
                    Phone      = custommer.Phone,
                    Email      = custommer.Email,
                    NRIC       = custommer.NRIC,
                    Avatar     = custommer.Avatar,
                    Name       = custommer.Name,
                    blackList  = custommer.blackList.GetValueOrDefault(0),
                    //Measurement = custommer.Measurement
                };
                return(new LogicResult <CustomerProfileDetail>()
                {
                    IsSuccess = true, Result = result
                });
            }
        }
Esempio n. 3
0
        public async Task <LogicResult> EditCustomer(CustomerProfileDetail customer)
        {
            var unitofwork = _repositoryHelper.GetUnitOfWork();
            var repo       = _repositoryHelper.GetRepository <ICustomerRepository>(unitofwork);

            var currentCustomer = repo.GetById(customer.ID);

            //hash password
            //var md5Pass = CreateMD5(customer.PassWord);

            currentCustomer.Name        = customer.Name;
            currentCustomer.DoB         = customer.DoB;
            currentCustomer.Gender      = customer.Gender;
            currentCustomer.Profression = customer.Profession;
            //currentCustomer.passWord = md5Pass;


            if (currentCustomer.Email == null)
            {
                currentCustomer.Email = customer.Email;
            }
            else if (currentCustomer.Email != customer.Email)
            {
                return new LogicResult <IEnumerable <CustomerProfileDetail> >()
                       {
                           IsSuccess = false, message = Validation.EmailCanNotChange
                       }
            }
            ;
            if (currentCustomer.Phone == null)
            {
                currentCustomer.Phone = customer.Phone;
            }
            else if (currentCustomer.Phone != customer.Phone)
            {
                return new LogicResult <IEnumerable <CustomerProfileDetail> >()
                       {
                           IsSuccess = false, message = Validation.PhoneCanNotChange
                       }
            }
            ;
            if (currentCustomer.NRIC == null)
            {
                currentCustomer.NRIC = customer.NRIC;
            }
            else if (currentCustomer.NRIC != customer.NRIC)
            {
                return new LogicResult <IEnumerable <CustomerProfileDetail> >()
                       {
                           IsSuccess = false, message = Validation.NRICCanNotChange
                       }
            }
            ;

            var updateField = new string[]
            {
                nameof(Customer.Email),
                nameof(Customer.Phone),
                nameof(Customer.Name),
                nameof(Customer.DoB),
                nameof(Customer.Gender),
                nameof(Customer.Profression),
                // nameof(Customer.passWord),
            };

            repo.Update(currentCustomer, updateField);
            var result = await unitofwork.SaveChangesAsync();

            if (!result)
            {
                return(new LogicResult()
                {
                    IsSuccess = false, message = Validation.ServerError
                });
            }
            return(new LogicResult()
            {
                IsSuccess = true
            });
        }