Beispiel #1
0
        public ActionResult Edit(mvcEmployeeModel model)
        {
            HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Test/" + model.EmployeeID, model).Result;

            TempData["SuccessMessage"] = "Profile Updated Successfully";
            return(RedirectToAction("Index"));
        }
 public ActionResult AddOrEdit(mvcEmployeeModel emp)
 {
     if (emp.EmployeeID == 0)
     {
         try
         {
             HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employee", emp).Result;
             if (response.IsSuccessStatusCode)
             {
                 TempData["SuccessMessage"] = "Saved Successfully";
             }
             else
             {
                 TempData["ErrorMessage"] = "Bad Request";
             }
         }
         catch (Exception ex)
         {
         }
     }
     else
     {
         HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Employee/" + emp.EmployeeID, emp).Result;
         if (response.IsSuccessStatusCode)
         {
             TempData["SuccessMessage"] = "Updated Successfully";
         }
         else
         {
             TempData["ErrorMessage"] = "Bad Request";
         }
     }
     return(RedirectToAction("Index"));
 }
Beispiel #3
0
        public ActionResult LoginUser(mvcEmployeeModel emp)
        {
            if (emp.USERNAME == "" && emp.USERPASSWORD == "")
            {
                TempData["Invalid"] = "Invalid Username or Password";
                return(View());
            }
            else
            {
                HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Account", emp).Result;
                mvcEmployeeModel    ee       = response.Content.ReadAsAsync <mvcEmployeeModel>().Result;

                if (ee == null)
                {
                    TempData["Invalid"] = "Username or Password is invalid please try with correct username or password";
                    return(View());
                }
                else
                {
                    Session["EMPLOYEEID"] = ee.EMPLOYEEID;
                    Session["NAME"]       = ee.NAME;
                    Session["ROLENAME"]   = ee.ROLENAME;
                    return(RedirectToAction("Index", "Employee"));
                }
            }
        }
Beispiel #4
0
        public ActionResult Create(mvcEmployeeModel emp)
        {
            HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Test", emp).Result;

            TempData["SuccessMessage"] = "New Profile Created Successfully";
            return(RedirectToAction("Index"));
        }
        public ActionResult Edite(mvcEmployeeModel emp)
        {
            HttpResponseMessage response = GlobalVariables.webclientApi.PutAsJsonAsync("Employees/" + emp.EmployeeID, emp).Result;

            TempData["Message"] = "Update Successfully ";

            return(RedirectToAction("Index"));
        }
        public ActionResult Add(mvcEmployeeModel emp)
        {
            HttpResponseMessage response = GlobalVariables.webclientApi.PostAsJsonAsync("Employees", emp).Result;

            TempData["Message"] = "Save Successfully ";

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(mvcEmployeeModel emp)
        {
            //Set message to be alerted after successful update
            TempData["successMessage"] = "Updated Successfully";

            //Post updated data with API
            HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Employee/" + emp.Id, emp).Result;

            return(RedirectToAction("Index"));
        }
        public ActionResult Create(mvcEmployeeModel dep)
        {
            //Set message to be alerted after successful creation
            TempData["successMessage"] = "Saved Successfully";

            //Post created employee record with API and redirect to Index
            HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employee", dep).Result;

            return(RedirectToAction("Index"));
        }
Beispiel #9
0
        public IActionResult UpdateEmployee(mvcEmployeeModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new InvalidOperationException("Model is not correct");
            }
            HttpResponseMessage responce = GlobalWebApiClientVariables.WebApiClient.PutAsJsonAsync($"EmployeeAPI/{model.EmployeeId}", model).Result;

            return(RedirectToAction("Index"));
        }
 public ActionResult AddOrEdit(mvcEmployeeModel emp)
 {
     if (emp.EmployeeID == 0)
     {
         HttpResponseMessage response = GlobalVariables.webApiClient.PostAsJsonAsync("api/Employee", emp).Result;
     }
     else
     {
         HttpResponseMessage response = GlobalVariables.webApiClient.PutAsJsonAsync("api/Employee/" + emp.EmployeeID, emp).Result;
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult AddorEdit(mvcEmployeeModel emp)
 {
     if (emp.EmployeeID == 0)
     {
         HttpResponseMessage response = GlobalVariables.webApiClient.PostAsJsonAsync("Employee", emp).Result;
         TempData["SuccessMessage"] = "Saved Successfully";
     }
     else
     {
         HttpResponseMessage response = GlobalVariables.webApiClient.PutAsJsonAsync("Employee/" + emp.EmployeeID, emp).Result;
         TempData["SuccessMessage"] = "Updated Successfully";
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult AddOrEdit(mvcEmployeeModel obj)
 {
     if (obj.EmployeeID == 0)
     {
         HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employees", obj).Result;
         TempData["SuccessMessage"] = "Saved successfully";
     }
     else
     {
         HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Employees/" + obj.EmployeeID, obj).Result;
         TempData["SuccessMessage"] = "Updated successfully";
     }
     return(RedirectToAction("Index"));
 }
Beispiel #13
0
 public ActionResult AddOrEdit(mvcEmployeeModel emp)
 {
     if (emp.EmployeeID == 0)                                                                                 // if id=0, we will do create operation
     {
         HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employee", emp).Result; // Getting The Post Method From WebApi
         TempData["SuccessMessage"] = "Saved Successfully";
     }
     else                                                                                                                      // else we will do update  Operation
     {
         HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Employee/" + emp.EmployeeID, emp).Result; // Getting the Post Operation
         TempData["SuccessMessage"] = "Updated Successfully";
     }
     return(RedirectToAction("Index"));
 }
        public ActionResult AddOrEdit(mvcEmployeeModel emp)//In order to insert operation we need to call http web api post method
        {
            if (emp.EmployeeId == 0)
            {
                HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employees", emp).Result;//this web api cal will insert new record into employee table and store the call result intoo "response" object
                TempData["SuccessMessage"] = "Saved Sucessfully";
            }

            else
            {
                HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Employees/" + emp.EmployeeId, emp).Result;//this web api cal will insert new record into employee table and store the call result intoo "response" object
                TempData["SuccessMessage"] = "Updated Sucessfully";
            }
            return(RedirectToAction("Index"));
        }
Beispiel #15
0
        public ActionResult AddOrUpdate(mvcEmployeeModel employeeModel)
        {
            var EmployeeID = employeeModel.EmployeeID;

            if (EmployeeID == 0)
            {
                HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Employee", employeeModel).Result;
                TempData["SuccessMessage"] = "Saved Successfully ...";
            }
            else
            {
                HttpResponseMessage response = GlobalVariables.WebApiClient.PutAsJsonAsync("Employee/" + EmployeeID, employeeModel).Result;
                TempData["SuccessMessage"] = "Updated Successfully ...";
            }

            return(RedirectToAction("Index"));
        }
 public ActionResult AddOrEdit(mvcEmployeeModel emp)
 {
     if (emp.EmployeeID == 0)
     {
         using (var client = new HttpClient())
         {
             client.BaseAddress = new Uri("http://localhost:64028/api/");
             var postTask = client.PostAsJsonAsync("Employee", emp);
             postTask.Wait();
             var result = postTask.Result;
             if (result.IsSuccessStatusCode)
             {
                 TempData["SuccessMessage"] = "Saved Successfully";
             }
             else
             {
                 TempData["SuccessMessage"] = "Save Failed";
             }
         }
     }
     else
     {
         using (var client = new HttpClient())
         {
             client.BaseAddress = new Uri("http://localhost:64028/api/");
             var postTask = client.PutAsJsonAsync("Employee/" + emp.EmployeeID, emp);
             postTask.Wait();
             var result = postTask.Result;
             if (result.IsSuccessStatusCode)
             {
                 TempData["SuccessMessage"] = "Updated Successfully";
             }
             else
             {
                 TempData["SuccessMessage"] = "Update Failed";
             }
         }
     }
     return(RedirectToAction("Index"));
 }