コード例 #1
0
        public async Task <IActionResult> Create(CreateCutomerViewModel model)
        {
            if (HttpContext.Session.GetString("IsEmployee") == null)
            {
                return(RedirectToAction("Login", "Authentication"));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                CreateCustomerSuccessViewModel createSuccess = new CreateCustomerSuccessViewModel();
                try
                {
                    var response = await _provider.CreateCustomer(model);

                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        var jsoncontent = await response.Content.ReadAsStringAsync();

                        createSuccess = JsonConvert.DeserializeObject <CreateCustomerSuccessViewModel>(jsoncontent);
                        return(View("CreateSuccess", createSuccess));
                    }
                    else if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                    {
                        ModelState.AddModelError("", "Having server issue while adding record");
                        return(View(model));
                    }
                    else if (response.StatusCode == System.Net.HttpStatusCode.Conflict)
                    {
                        ModelState.AddModelError("", "Username already present with ID :" + model.CustomerId);
                        return(View(model));
                    }
                    else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                    {
                        ModelState.AddModelError("", "Invalid model states");
                        return(View(model));
                    }
                }catch (Exception ex)
                {
                    _logger.Error("Exception Occured as : " + ex.Message);
                }
                return(View(model));
            }
        }
コード例 #2
0
 public async Task <ActionResult <HttpStatusCode> > CreateCustomer(Customer customer)
 {
     return(await customerProvider.CreateCustomer(customer));
 }