예제 #1
0
        public JsonResult AddCustomer(CustomerModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool ifExists = false;
                    if (!ifExists)
                    {
                        var customer = new Customer();
                        customer.LastName = model.LastName;
                        customer.MiddleName = model.MiddleName;
                        customer.FirstName = model.FirstName;
                        customer.Active = true;
                        customer.Gender = model.Gender;
                        customer.BirthDate = Convert.ToDateTime(model.BirthDate);
                        customer.CellphoneNo = model.CellphoneNo;
                        customer.Email = model.Email;
                        customer.ResidentialAddress = model.ResidentialAddress;
                        customer.OfficeAddress = model.OfficeAddress;
                        customer.TypeOfID = model.TypeOfID;
                        customer.IDNo = model.IDNo;
                        customer.DateCreated = DateTime.Now;
                        customer.CreatedBy = User.Identity.Name;

                        _customerService.Create(customer);

                        return
                            Json(
                                new
                                {
                                    result = customer.Id.ToString(),
                                    message = MessageCode.saved,
                                    code = StatusCode.saved,
                                    content =
                                        Base.GenerateFullName(customer.FirstName, customer.MiddleName, customer.LastName)
                                });
                    }
                    return
                        Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed });
                }
                return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid });
            }
            catch (Exception ex)
            {
                return
                    Json(
                        new
                        {
                            result = StatusCode.failed,
                            message = ex.Message,
                            code = StatusCode.failed,
                            content = ex.Message
                        });
            }
        }
예제 #2
0
 public ActionResult Customer()
 {
     var model = new CustomerModel();
     return View(model);
 }