Exemple #1
0
        public async Task <IActionResult> Post([FromBody] CustomerModel model)
        {
            var customer = model.CastOrFill <CustomerInfo>();

            using (var writer = new StoredProcedureWriter <CustomerInfo>(customer, new CustomerSPConfig(customer)))
            {
                customer = await writer.SaveAsync();
            }
            return(Ok(customer.CastOrFill <CustomerModel>()));
        }
Exemple #2
0
        public ActionResult Create(CustomerModel model)
        {
            var customer = model.CastOrFill <CustomerInfo>();

            customer = customer.Save();
            if (!customer.IsNew)
            {
                TempData[ResultMessage] = "Successfully created";
            }
            else
            {
                TempData[ResultMessage] = "Failed to create";
            }

            return(View(CustomerController.SummaryView, customer.CastOrFill <CustomerModel>()));
        }
Exemple #3
0
        public ActionResult Edit(CustomerModel model)
        {
            var reader   = new EntityReader <CustomerInfo>();
            var customer = model.CastOrFill <CustomerInfo>();

            customer = customer.Save();
            if (!customer.IsNew)
            {
                TempData[ResultMessage] = "Successfully saved";
            }
            else
            {
                TempData[ResultMessage] = "Failed to save";
            }

            return(View(CustomerController.SummaryView, customer.CastOrFill <CustomerModel>()));
        }
Exemple #4
0
        public async Task <ActionResult> Edit(CustomerModel model)
        {
            var customer = model.CastOrFill <CustomerInfo>();

            using (var writer = new StoredProcedureWriter <CustomerInfo>(customer, new CustomerSPConfig(customer)))
            {
                customer = await writer.SaveAsync();
            }
            if (!customer.IsNew)
            {
                TempData[ResultMessage] = "Successfully saved";
            }
            else
            {
                TempData[ResultMessage] = "Failed to save";
            }

            return(View(CustomerController.SummaryView, customer.CastOrFill <CustomerModel>()));
        }
        public ActionResult Search(CustomerModel data)
        {
            var model = new CustomerSearchModel();
            IQueryable <CustomerInfo> searchResults;

            model = data.CastOrFill <CustomerSearchModel>();
            using (var reader = new EntityReader <CustomerInfo>())
            {
                searchResults = reader.GetAll()
                                .Where(x => (model.FirstName != Defaults.String && x.FirstName.Contains(model.FirstName)) ||
                                       (model.LastName != Defaults.String && x.LastName.Contains(model.LastName)) ||
                                       (model.BirthDate != Defaults.Date && x.BirthDate == model.BirthDate) ||
                                       (x.Id == model.Id)).Take(25);
            }
            if (searchResults.Any())
            {
                model.Results.FillRange(searchResults);
            }
            TempData[ResultMessage] = $"{model.Results.Count} matches found";

            return(View(CustomerSearchController.SearchView, model));
        }