Exemple #1
0
        //Method to get Customers with Customer ID


        //Method to create customer
        public ReturnMessage <Customers_VM> CreateNewCustomer(Customers_VM customer)
        {
            var CreateCustomer = new ReturnMessage <Customers_VM>();

            var Creatusermap = mapper.Map <Customers_VM, Customers>(customer);

            Creatusermap.User_Type = (int)customer.UserType;
            var dbConnection = DatabaseUtilities.GetSQLConnection(GetConfig.ConnectionString);
            var paras        = new Dictionary <string, string>
            {
                { "@Email", Creatusermap.Email },

                { "@User_Name", Creatusermap.User_Name },

                { "@First_Name", Creatusermap.First_Name },

                { "@Last_Name", Creatusermap.Last_Name },

                { "@Phone_Number", Creatusermap.Phone_Number },

                { "@User_Type", Creatusermap.User_Type.ToString() },
            };


            var returnMessage = Repo <ReturnMessage <Customers_VM> > .GetObject(dbConnection, paras, "proc_tblCustomers_AddCustomer",
                                                                                CommandType.StoredProcedure);

            logger.Information($"Response from DB  to create  Customer  => {JsonConvert.SerializeObject(returnMessage)}");

            if (returnMessage.ResponseCode == "1")
            {
                CreateCustomer.ResponseCode        = "00";
                CreateCustomer.ResponseDescription = "Success";
                CreateCustomer.Body        = customer;
                CreateCustomer.Body.UserID = returnMessage.Id;
            }
            else if (returnMessage.ResponseCode == "2")
            {
                CreateCustomer.ResponseCode        = "01";
                CreateCustomer.ResponseDescription = $"Unable to save record => {returnMessage.ResponseDescription}";
            }

            else
            {
                CreateCustomer.ResponseDescription = "96";
                CreateCustomer.ResponseDescription = "Unable to save customer Records";
            }

            return(CreateCustomer);
        }
        public ReturnMessage <Customers_VM> Post([FromBody] Customers_VM Customer_Dets)
        {
            logger.Information($"Received request to CreateCustomer => {JsonConvert.SerializeObject(Customer_Dets)}");

            var CustomerCreateResult = new ReturnMessage <Customers_VM>();

            try
            {
                //var customerCore = new CustomerCore(mapper, logger);
                if (ModelState.IsValid)
                {
                    CustomerCreateResult = customerCore1.CreateNewCustomer(Customer_Dets);

                    if (CustomerCreateResult.ResponseCode == "01")

                    {
                        Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    var errorList = (from item in ModelState.Values
                                     from error in item.Errors
                                     select error.ErrorMessage).ToArray();

                    CustomerCreateResult.ResponseDescription = String.Join('|', errorList);
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                }
            }
            catch (Exception ex)
            {
                logger.Debug(ex, "Error creating Customer ");

                CustomerCreateResult.ResponseCode        = "96";
                CustomerCreateResult.ResponseDescription = "Unable to create PassengerInfo";
            }
            return(CustomerCreateResult);
        }