Exemple #1
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (sampleEntities entities = new sampleEntities())
         {
             var entity = (entities.Employees.FirstOrDefault(e => e.ID == id));
             if (entity != null)
             {
                 entities.Employees.Remove(entity);
                 entities.SaveChanges();
                 var message = Request.CreateResponse(HttpStatusCode.OK, "deleted");
                 return(message);
             }
             else
             {
                 var message = Request.CreateResponse(HttpStatusCode.NotFound, "cannot be found");
                 return(message);
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Exemple #2
0
 public HttpResponseMessage Put(int id, Employee employee)
 {
     try
     {
         using (sampleEntities entities = new sampleEntities())
         {
             var entity = entities.Employees.FirstOrDefault(e => e.ID == id);
             if (entity != null)
             {
                 entity.FirstName = employee.FirstName;
                 entity.LastName  = employee.LastName;
                 entity.Gender    = employee.Gender;
                 entity.Salary    = employee.Salary;
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "not found"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Exemple #3
0
 public static void Removefromdb(Employee Selectedemp)
 {
     if (Selectedemp == null)
     {
         return;
     }
     using (sampleEntities db = new sampleEntities())
     {
         db.employee.RemoveRange(db.employee.Where(c => c.emp_no == Selectedemp.Emp_no));
         db.SaveChanges();
     }
 }
 public string AddEmployee(employee1 Emp)
 {
     if (Emp != null)
     {
         using (sampleEntities dataContext = new sampleEntities())
         {
             dataContext.employee1.Add(Emp);
             dataContext.SaveChanges();
             return("Employee Updated");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
Exemple #5
0
 public static void Addtodb(Employee e)
 {
     /// <param name="Int2">Used to indicate status.</param>
     using (sampleEntities db = new sampleEntities())
     {
         db.employee.Add(new employee
         {
             emp_no    = e.Emp_no,
             emp_fname = e.Emp_fname,
             emp_lname = e.Emp_lname,
             salary    = e.Salary,
             dept_no   = e.Dept_no
         });
         db.SaveChanges();
     }
 }
 public string DeleteEmployee(employee1 Emp)
 {
     if (Emp != null)
     {
         using (sampleEntities dataContext = new sampleEntities())
         {
             int no           = Convert.ToInt32(Emp.id);
             var employeeList = dataContext.employee1.Where(x => x.id == no).FirstOrDefault();
             dataContext.employee1.Remove(employeeList);
             dataContext.SaveChanges();
             return("Employee Deleted");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
Exemple #7
0
 public HttpResponseMessage Post(Employee employee)
 {
     try
     {
         using (sampleEntities entities = new sampleEntities())
         {
             entities.Employees.Add(employee);
             entities.SaveChanges();
         }
         var message = Request.CreateResponse(HttpStatusCode.Created, employee);
         message.Headers.Location = new Uri(Request.RequestUri + "/" + employee.ID.ToString());
         return(message);
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] UserDetail user)
        {
            bool   status  = false;
            string message = "";

            //Model Validation
            if (ModelState.IsValid)
            {
                //Email is already exists
                var isExist = IsEmailExist(user.EmailID);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                //Generate Activation Code
                user.ActivtionCode = Guid.NewGuid();

                //password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);

                user.IsEmailVerified = false;
                //Save to database
                using (sampleEntities dc = new sampleEntities())
                {
                    dc.UserDetails.Add(user);
                    dc.SaveChanges();

                    //Send Email to User
                    /*  SendVerificationLinkEmail(user.EmailID, user.ActivtionCode.ToString());*/
                    message = "Registration successfully done. ";
                    status  = true;
                }
            }
            else
            {
                message = "Invalid Request";
            }
            ViewBag.Message = message;
            ViewBag.Status  = status;
            return(View(user));
        }
 public string UpdateEmployee(employee1 Emp)
 {
     if (Emp != null)
     {
         using (sampleEntities dataContext = new sampleEntities())
         {
             int no           = Convert.ToInt32(Emp.id);
             var employeeList = dataContext.employee1.Where(x => x.id == no).FirstOrDefault();
             employeeList.name      = Emp.name;
             employeeList.mobile_no = Emp.mobile_no;
             employeeList.email     = Emp.email;
             dataContext.SaveChanges();
             return("Employee Updated");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
 public void Save()
 {
     Context.SaveChanges();
 }