Пример #1
0
 public ActionResult Index(CustomerTrainings model, string btnValue)
 {
     _customerService = new CustomerService();
     if (model != null)
     {
         if (model.StartDate != null && model.EndDate != null)
         {
             model.DateTimeDifference = Convert.ToInt32((model.EndDate - model.StartDate).Value.TotalDays);
         }
         else
         {
             model.DateTimeDifference = 0;
         }
         if (model.StartDate > model.EndDate)
         {
             model.ErrorMessage = _customerService.Message(false, model.DateTimeDifference, model.StartDate.Value, model.EndDate.Value);
         }
         if (model.ErrorMessage == "")
         {
             var isValid = _customerService.InsertCustomerTraining(model);
             model.SuccessMessage = _customerService.Message(isValid, model.DateTimeDifference, model.StartDate.Value, model.EndDate.Value);
         }
     }
     return(View(model));
 }
Пример #2
0
        public void PostIndexMethodGetErrorMessage()
        {
            //Arrange
            CustomerController training = new CustomerController();
            //Setting Model Property
            CustomerTrainings model = new CustomerTrainings()
            {
                TrainingName = "Test",
                StartDate    = Convert.ToDateTime("08/08/2019"),
                EndDate      = Convert.ToDateTime("10/08/2019"),
            };
            //Act
            ViewResult result = training.Index(model, string.Empty) as ViewResult;
            //ServiceCall
            CustomerService service = new CustomerService();
            var             valid   = service.InsertCustomerTraining(model);

            if (!valid)
            {
                Assert.IsTrue(valid, "UnSuccessfull");
            }
        }
Пример #3
0
        public bool InsertCustomerTraining(CustomerTrainings model)
        {
            bool isValid = false;

            try
            {
                if (model != null)
                {
                    SqlConnection conn = new SqlConnection("@Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Arunkumar\\documents\\visual studio 2015\\Projects\\WebApplication1\\WebApplication2\\App_Data\\DatabaseLocal.mdf;Integrated Security=True");
                    SqlCommand    cmd  = new SqlCommand("Insert into CustomerTraining (TrainingName,StartDate,EndDate,DateDifference) values('" + model.TrainingName + "','" + model.StartDate + "','" + model.EndDate + "','" + model.DateTimeDifference + "')", conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    isValid = true;
                }
            }
            catch (Exception ex)
            {
                isValid = false;
                throw ex;
            }
            return(isValid);
        }
Пример #4
0
        public ActionResult Index()
        {
            CustomerTrainings model = new CustomerTrainings();

            return(View(model));
        }