예제 #1
0
 public static void UpdateCustomer(this Customer customer, CustomerViewModel customerVm)
 {
     customer.FirstName = customerVm.FirstName;
     customer.LastName = customerVm.LastName;
     customer.IdentityCard = customerVm.IdentityCard;
     customer.Mobile = customerVm.Mobile;
     customer.DateOfBirth = customerVm.DateOfBirth;
     customer.Email = customerVm.Email;
     customer.UniqueKey = (customerVm.UniqueKey == null || customerVm.UniqueKey == Guid.Empty)
         ? Guid.NewGuid() : customerVm.UniqueKey;
     customer.RegistrationDate = (customer.RegistrationDate == null || customer.RegistrationDate.Equals(DateTime.MinValue) ? DateTime.Now : customerVm.RegistrationDate);
 }
예제 #2
0
        public HttpResponseMessage Register(HttpRequestMessage request, CustomerViewModel customer)
        {
            return this.CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (ModelState.IsValid)
                {
                    if (customerRepository.FindBy(customerToFind =>
                    {
                        return customerToFind.Email.Equals(customer.Email) ||
                               customerToFind.IdentityCard.Equals(customer.IdentityCard);
                    }
                    ).Count() != 0)
                    {
                        ModelState.AddModelError("Invalid User", "User with such Email/IC exists");
                        response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                    }
                    else
                    {
                        Customer tempCustomer = new Customer();
                        tempCustomer.UpdateCustomer(customer);
                        customerRepository.Add(tempCustomer);
                        unitOfWork.Commit();

                        response = request.CreateResponse(HttpStatusCode.OK,
                            Mapper.Map<Customer, CustomerViewModel>(tempCustomer));
                    }

                }
                else
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                }

                return response;
            });
        }
예제 #3
0
        public HttpResponseMessage Update(HttpRequestMessage request, CustomerViewModel customer)
        {
            return this.CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    Customer tempCustomer = customerRepository.GetSingle(customer.Id);
                    tempCustomer.UpdateCustomer(customer);
                    unitOfWork.Commit();

                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                else
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray());
                }

                return response;
            });
        }