예제 #1
0
 public EmpDTO SaveEmployee(EmpDTO obj)
 {
     using (DeveloperEntities DB = new DeveloperEntities())
     {
         using (var dbContextTransaction = DB.Database.BeginTransaction())
         {
             try
             {
                 DB.Configuration.ProxyCreationEnabled = false;
                 DB.Configuration.LazyLoadingEnabled   = false;
                 if (obj == null)
                 {
                     throw new ArgumentNullException("item");
                 }
                 DB.InsertEmployee(0, obj.EmpName, obj.Salary, obj.DeptName, obj.Designation, obj.EmpFile, obj.UserName, obj.Password, OutputParamValue);
                 obj.ResultID = Convert.ToString(OutputParamValue.Value);
                 DB.SaveChanges();
                 dbContextTransaction.Commit();
                 return(obj);
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 throw;
             }
         }
     }
 }
예제 #2
0
 private void butnSignIn_Click(object sender, EventArgs e)
 {
     if (textUserName.Text == "")
     {
         MessageBox.Show("Please enter username");
     }
     else if (textPassword.Text == "")
     {
         MessageBox.Show("Please enter password");
     }
     else
     {
         int    EmpID = Convert.ToInt32(textUserName.Text);
         EmpDTO emp   = new EmpDTO(EmpID, textPassword.Text);
         if (bus.CheckAccount(emp) == 1)
         {
             this.Close();
             th = new Thread(openNextForm);
             th.SetApartmentState(ApartmentState.STA);
             th.Start();
         }
         else if (bus.CheckAccount(emp) == 2)
         {
             this.Close();
             th = new Thread(openAdminForm);
             th.SetApartmentState(ApartmentState.STA);
             th.Start();
         }
         else
         {
             MessageBox.Show("Wrong password or username");
         }
     }
 }
예제 #3
0
        private void btnAddEmp_Click(object sender, EventArgs e)
        {
            if (txtEName.Text != "" && txtEPass.Text != "" && cbERole.Text != "" && cbEStatus.Text != "")
            {
                EmpDTO emp_DTO = new EmpDTO()
                {
                    EmployeeName = txtEName.Text, password = txtEPass.Text, Status = cbEStatus.Text, IsAdmin = cbERole.Text
                };
                if (emp_BUS.InsertEmp(emp_DTO))
                {
                    MessageBox.Show("Adding success");
                }
                else
                {
                    MessageBox.Show("Adding fail");
                }
            }
            else
            {
                MessageBox.Show("Please fill required data");
            }

            EmployeeManagement_Load(sender, e);
            ClearData();
        }
예제 #4
0
        public ActionResult Login(EmpDTO obj)
        {
            try
            {
                var client = new HttpClient();

                // var FillLogin = client.GetAsync("http://localhost:6198/api/EmpApi/GetEmp").Result
                var FillLogin = client.GetAsync(ConfigurationManager.AppSettings["APIURL"] + "/api/EmpApi/GetEmp").Result
                                .Content.ReadAsAsync <List <EmpDTO> >().Result.Where(item => item.UserName == obj.UserName && item.Password == obj.Password).SingleOrDefault();

                //var MyEmpDate = new EmpDTO
                //{
                //    UserName = FillLogin.UserName,
                //};

                if (FillLogin == null)
                {
                    return(RedirectToAction("Login", "Emp"));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #5
0
        public int CheckAccount(EmpDTO emp)
        {
            con.Open();
            string        SQL = string.Format("SELECT * FROM employee WHERE EmployeeID = {0} AND [Password] = {1}", emp.EmployeeID, emp.password);
            SqlCommand    cmd = new SqlCommand(SQL, con);
            SqlDataReader rd  = cmd.ExecuteReader();
            int           loginSuccessful;

            rd.Read();
            if (rd.HasRows)
            {
                if (rd["IsAdmin"].ToString() == "admin")
                {
                    loginSuccessful = 2;
                }
                else
                {
                    loginSuccessful = 1;
                }
            }
            else
            {
                loginSuccessful = 0;
            }
            con.Close();
            return(loginSuccessful);
        }
예제 #6
0
        public bool InsertEmp(EmpDTO emp)
        {
            try
            {
                con.Open();

                string SQL = string.Format("Insert into Employee(EmployeeName,[Password],[Status],IsAdmin) values ('{0}','{1}','{2}','{3}')", emp.EmployeeName, emp.password, emp.Status, emp.IsAdmin);

                SqlCommand cmd = new SqlCommand(SQL, con);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }

            catch (Exception e)
            { }

            finally
            {
                con.Close();
            }

            return(false);
        }
예제 #7
0
        public HttpResponseMessage SaveEmployee(EmpDTO obj)
        {
            obj = EmpRep.SaveEmployee(obj);
            var Responce = Request.CreateResponse <EmpDTO>(HttpStatusCode.Created, obj);

            Responce.ReasonPhrase = Convert.ToString(obj.ResultID);
            return(Responce);
        }
예제 #8
0
        public Employee GetModel(EmpDTO emp)
        {
            Employee obj = new Employee();

            obj.empid     = emp.empid;
            obj.firstname = emp.firstnm;
            obj.lastname  = emp.lastnm;
            obj.mobileno  = emp.mob;
            obj.gender    = emp.gender;
            obj.state     = emp.state;
            obj.city      = emp.city;
            return(obj);
        }
예제 #9
0
        public HttpResponseMessage GetEmp(int id)
        {
            EmpDTO ObjCon = EmpRep.Get(id);

            if (ObjCon == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Sorry"));
            }
            else
            {
                return(Request.CreateResponse <EmpDTO>(ObjCon));
            }
        }
예제 #10
0
        public ActionResult GetEmployee(EmpDTO objDTO)
        {
            var client = new HttpClient();

            if (objDTO.EmpName != null)
            {
                var response = client.PostAsJsonAsync("http://localhost:6198/api/EmpApi/GetEmpDetails", objDTO).Result;

                if (response.IsSuccessStatusCode)
                {
                }
            }
            return(View());
        }
 // POST: api/Employee
 /// <summary>
 /// Add new Employee
 /// </summary>
 public HttpStatusCode Add([FromBody] EmpDTO newEmp)
 {
     try
     {
         Employee emp = new Employee()
         {
             Name = newEmp.Name, Age = newEmp.Age, HiringDate = newEmp.HiringDate
         };
         db.Employees.Add(emp);
         db.SaveChanges();
         return(HttpStatusCode.OK);
     }
     catch (Exception)
     {
         return(HttpStatusCode.InternalServerError);
     }
 }
예제 #12
0
        private void butnSignIn_Click(object sender, EventArgs e)
        {
            int EmpID = int.Parse(textUserName.Text);

            EmpDTO emp = new EmpDTO()
            {
                EmployeeID = EmpID, password = textPassword.Text
            };

            if (textUserName.Text == "")
            {
                MessageBox.Show("Please enter username");
            }
            else if (textPassword.Text == "")
            {
                MessageBox.Show("Please enter password");
            }
            else
            {
                Session.instance.Emp = new EmpBUS().Get(EmpID);
                if (bus.CheckAccount(emp) == 1)
                {
                    this.Close();
                    th = new Thread(openNextForm);
                    th.SetApartmentState(ApartmentState.STA);
                    th.Start();
                }
                else if (bus.CheckAccount(emp) == 2)
                {
                    this.Close();
                    th = new Thread(openAdminForm);
                    th.SetApartmentState(ApartmentState.STA);
                    th.Start();
                }
                else
                {
                    MessageBox.Show("Wrong password or username");
                }
            }
        }
예제 #13
0
        private void btnUpdateEmp_Click(object sender, EventArgs e)
        {
            if (txtSearchEmp.Text != "" && txtEName.Text != "" && cbERole.Text != "" && cbEStatus.Text != "")
            {
                int    EmpID   = int.Parse(txtSearchEmp.Text);
                EmpDTO emp_DTO = new EmpDTO(EmpID, txtEName.Text, cbERole.Text, cbEStatus.Text);
                if (emp_BUS.UpdateEmp(emp_DTO))
                {
                    MessageBox.Show("Updated successfully");
                }
                else
                {
                    MessageBox.Show("Updating fail");
                }
            }
            else
            {
                MessageBox.Show("Please fill required data");
            }

            EmployeeManagement_Load(sender, e);
        }
예제 #14
0
        /*Update Employee*/
        public bool UpdateEmp(EmpDTO emp)
        {
            try
            {
                con.Open();

                string SQL = string.Format("Update Employee(EmployeeName,[Status],IsAdmin) " + "set EmployeeName = '{0}', [Status] = '{1}', IsAdmin = '{2}' where EmployeeID = {3}",
                                           emp.EName, emp.Status, emp.Role, emp.EID);

                SqlCommand cmd = new SqlCommand(SQL, con);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }

            catch (Exception e)
            { }
            finally
            {
                con.Close();
            }
            return(false);
        }
예제 #15
0
 public bool UpdateEmp(EmpDTO emp)
 {
     return(dal.UpdateEmp(emp));
 }
예제 #16
0
        /// <summary>
        /// update method to update the records of the EmployeeBAL datatable
        /// </summary>

        public void UpdateEmployeeBAL(EmpDTO em)
        {
            emp.UpdateEmployee(map.GetModel(em));
        }
예제 #17
0
        /// <summary>
        /// delete method to delete data from the EmployeeBAL datatable
        /// </summary>
        /// <param name="user"></param>

        public void DeleteEmployeeBAL(EmpDTO em)
        {
            emp.DeleteEmployee(map.GetModel(em));
        }
예제 #18
0
        /// <summary>
        /// add method for performing add operations in our EmployeeBALform
        /// </summary>

        public void AddEmployeeBAL(EmpDTO em)
        {
            emp.AddEmployee(map.GetModel(em));
        }
예제 #19
0
 public bool InsertEmp(EmpDTO emp)
 {
     return(dal.InsertEmp(emp));
 }
예제 #20
0
        public ActionResult SaveEmployee(EmpDTO objDTO, List <HttpPostedFileBase> fileUpload)
        {
            #region FileUpload
            List <string> myTempPaths = new List <string>();
            ModelState.Clear();
            if (fileUpload.Count > 1)
            {
                int i            = 0;
                var ErrorMessage = string.Empty;

                int cnts = 0;

                foreach (HttpPostedFileBase file in fileUpload)
                {
                    if (objDTO.DocDTO.DocName != null)
                    {
                        if (file != null && Array.Exists(objDTO.DocDTO.DocName.Split(','), s => s.Equals(file.FileName)))
                        {
                            int      MaxContentLength      = 1024 * 1024 * 3; //3 MB
                            string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png" };
                            if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                            {
                                ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions));

                                ErrorMessage = "Please upload Your File of type: " + string.Join(", ", AllowedFileExtensions);
                                // TempData["error"] = ("Please file of type: " + string.Join(", ", AllowedFileExtensions));
                                TempData["error"] = ErrorMessage;
                                return(RedirectToAction("TicketsAdd"));
                                // return ("TicketsEdit",TempData["error"].ToString());
                            }
                            else if (file.ContentLength > MaxContentLength)
                            {
                                ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB");

                                ErrorMessage      = "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB";
                                TempData["error"] = ErrorMessage;
                                return(RedirectToAction("TicketsAdd"));
                            }
                            else
                            {
                                string extension = Path.GetExtension(file.FileName);
                                var    fileName  = Path.GetFileName(file.FileName);
                                //  GetTicketAttachment(Convert.ToInt32(0));

                                /*  for (int l = 0; l < ViewBag.AllTicketAttachment.Count; l++)
                                 * {
                                 *    if (ViewBag.AllTicketAttachment[l].FileName == fileName)
                                 *    {
                                 *        cnts++;
                                 *    }
                                 * }*/
                                if (cnts > 0)
                                {
                                    ModelState.AddModelError("File", "Your file is already exist");
                                    ErrorMessage      = "Your file is already exist";
                                    TempData["error"] = ErrorMessage;
                                    string url = this.Request.UrlReferrer.AbsolutePath;
                                    return(Redirect(url));
                                }
                                else
                                {
                                    file.SaveAs(Path.Combine(Server.MapPath("~/Upload"), fileName));
                                    ModelState.Clear();
                                    myTempPaths.Add(fileName);
                                    i++;
                                }
                            }
                        }
                    }
                }
            }

            var count = myTempPaths.Count;
            #endregion



            using (var client = new HttpClient())
            {
                //client.BaseAddress = new Uri("http://localhost:6198/");
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["APIURL"]);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = client.PostAsJsonAsync("api/EmpApi/SaveEmployee/", objDTO).Result;
                var test = Convert.ToString(response.ReasonPhrase);
                if (!response.IsSuccessStatusCode)
                {
                    // Error Over Here....!!
                    return(View("Error"));
                }



                for (int i = 0; i < count; i++)
                {
                    objDTO.DocDTO.DocName = myTempPaths[i];
                    objDTO.DocDTO.EmpNo   = Convert.ToInt32(response.ReasonPhrase);
                    //client.BaseAddress = new Uri("http://localhost:6198/");
                    client.BaseAddress = new Uri(ConfigurationManager.AppSettings["APIURL"]);


                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    HttpResponseMessage response1 = client.PostAsJsonAsync("api/EmpApi/AddDoc/", objDTO).Result;
                    if (response1.IsSuccessStatusCode)
                    {
                        //  .. cnt++;
                    }
                }


                // var objtDTO = response.Content.ReadAsAsync<IEnumerable<EmpDTO>>().Result;
                return(View("SaveEmployee"));
            }
        }
예제 #21
0
 public int CheckAccount(EmpDTO emp)
 {
     return(dal.CheckAccount(emp));
 }