Ejemplo n.º 1
0
 public List <Employee> GetAllData()
 {
     using (con)
     {
         try
         {
             con.Open();
             cmd = new SqlCommand("uspGetAllDataTemptble", con)
             {
                 CommandType = CommandType.StoredProcedure
             };
             reader = cmd.ExecuteReader();
             List <Employee> employees = new List <Employee>();
             while (reader.Read())
             {
                 employees.Add(new Employee
                 {
                     Id               = Convert.ToInt32(reader["id"]),
                     Date             = Convert.ToDateTime(reader["date"]),
                     Name             = Convert.ToString(reader["name"]),
                     Salary           = Convert.ToDecimal(reader["salary"]),
                     CalculatedSalary = Convert.ToDecimal(GetSafeValue(reader["calculatedSalary"])),
                     YearsInAdapty    = Convert.ToDouble(GetSafeValue(reader["yearsInAdapty"]))
                 });
             }
             ;
             return(employees);
         }
         catch (Exception ex)
         {
             ExLogger.Logger(ex, con);
             return(null);
         }
     }
 }
Ejemplo n.º 2
0
        public bool Save(Employee employee)
        {
            using (con)
            {
                try
                {
                    con.Open();
                    cmd             = new SqlCommand("uspInsertTemptble", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@name", employee.Name);
                    cmd.Parameters.AddWithValue("@salary", employee.Salary);
                    cmd.Parameters.AddWithValue("@yearsInAdapty", employee.YearsInAdapty);

                    cmd.ExecuteNonQuery();

                    return(true);
                }
                catch (Exception ex)
                {
                    ExLogger.Logger(ex, con);
                }
                //cannot write return false; in finally block because finally block cannot have return
            }
            return(false);
        }
Ejemplo n.º 3
0
        public bool Update(Employee employee)
        {
            using (con)
            {
                try
                {
                    con.Open();
                    cmd = new SqlCommand("uspUpdateTemptble", con)
                    {
                        CommandType = CommandType.StoredProcedure
                    };
                    cmd.Parameters.AddWithValue("@id", employee.Id);
                    cmd.Parameters.AddWithValue("@name", employee.Name);
                    cmd.Parameters.AddWithValue("@salary", employee.Salary);
                    cmd.Parameters.AddWithValue("@yearsInAdapty", employee.YearsInAdapty);

                    cmd.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception ex)
                {
                    ExLogger.Logger(ex, con);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
 public ActionResult Delete(Employee employee)
 {
     try
     {
         // TODO: Add delete logic here
         employees.Delete(employee);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ExLogger.Logger(ex, @"D:\ErrorLog.txt");
         return(View(ex.Message));
     }
 }
Ejemplo n.º 5
0
 public ActionResult Edit(Employee employee)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     try
     {
         // TODO: Add update logic here
         employees.Update(employee);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ExLogger.Logger(ex, @"D:\ErrorLog.txt");
         return(View(ex.Message));
     }
 }
Ejemplo n.º 6
0
 public ActionResult Create(Employee employee)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     try
     {
         // TODO: Add insert logic here
         employees.Create(employee);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ExLogger.Logger(ex, @"D:\ErrorLog.txt");
         return(View("Error"));
     }
 }
Ejemplo n.º 7
0
        public bool Delete(Employee employee)
        {
            using (con)
            {
                try
                {
                    con.Open();
                    cmd             = new SqlCommand("uspDeleteTemptble", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@id", employee.Id);

                    cmd.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception ex)
                {
                    ExLogger.Logger(ex, con);
                }
            }
            return(false);
        }