public HttpResponseMessage Post([FromBody] EmployeeModel value)
        {
            bool check = ModelState.IsValid;

            if (!check)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Required ALL Information"));
            }
            try
            {
                Employee emp = new Employee()
                {
                    Name        = value.Name,
                    PhoneNumber = value.PhoneNumber,
                    Email       = value.Email,
                    DateofBirth = value.DOB,
                    IsMale      = value.isMale,
                    Age         = value.Age,
                    State       = value.state.ID,
                    State1      = dbContext.States.Single(p => p.StateID == value.state.ID)
                };
                foreach (var item in value.edu)
                {
                    emp.Educations.Add(dbContext.Educations.Find(item.ID));
                }
                dbContext.Employees.Add(emp);
                dbContext.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK, "Completed"));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Something Went Wrong!"));
            }
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "EmployeeId,First_Name,Last_Name,Position,Age,Salary")] MvcEmployeeModel mvcEmployeeModel)
        {
            //    if (ModelState.IsValid)
            //    {
            //        mvcEmployeeModel.EmployeeId = Guid.NewGuid();
            //        db.EmployeeModels.Add(mvcEmployeeModel);
            //        db.SaveChanges();
            //        return RedirectToAction("Index");
            //    }

            //    return View(mvcEmployeeModel);
            //}

            mvcEmployeeModel.EmployeeId = Guid.NewGuid();
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors })
                         .ToArray();

            if (ModelState.IsValid)
            {
                db.EmployeeModels.Add(mvcEmployeeModel);

                db.SaveChanges();
            }
            return(View(mvcEmployeeModel));
        }
Пример #3
0
        public ActionResult <string> CreateEmployee()
        {
            string   employeeJson = new StreamReader(Request.Body).ReadToEnd();
            Employee employee     = JsonConvert.DeserializeObject <Employee>(employeeJson);

            _context.Add(employee);
            _context.SaveChanges();
            return("success");
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "id,firstName,lastName,phoneNo,homeAddress,email,dob,jobTitle,privilege,password,username")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.name = AdministratorController.staticName;
            return(View(employee));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "id,date,status,employeeId")] DayOff dayOff)
        {
            if (ModelState.IsValid)
            {
                db.DayOffs.Add(dayOff);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.employeeId = new SelectList(db.Employees, "id", "firstName", dayOff.employeeId);
            ViewBag.name       = AdministratorController.staticName;
            return(View(dayOff));
        }
Пример #6
0
        public ActionResult Create([Bind(Include = "id,startDate,endDate,status,employeeId")] Leave leave)
        {
            if (ModelState.IsValid)
            {
                db.Leaves.Add(leave);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.employeeId = new SelectList(db.Employees, "id", "firstName", leave.employeeId);
            ViewBag.name       = AdministratorController.staticName;
            return(View(leave));
        }
Пример #7
0
        public ActionResult Create([Bind(Include = "id,date,attendance,employeeId")] Shift shift)
        {
            if (ModelState.IsValid)
            {
                db.Shifts.Add(shift);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.employeeId = new SelectList(db.Employees, "id", "firstName", shift.employeeId);
            ViewBag.name       = AdministratorController.staticName;
            return(View(shift));
        }
        public bool AddDepartment(Department dept)
        {
            int isAvailable = db.Departments.Where(m => m.Name == dept.Name).Count();

            if (isAvailable > 0)
            {
                return(false);
            }
            else
            {
                db.Departments.Add(dept);
                return(db.SaveChanges() > 0);
            }
        }
Пример #9
0
        static public void PeopleSeed()
        {
            EmployeeManagementContext db = new EmployeeManagementContext();

            Employee emp;
            Random   rnd = new Random();

            for (int i = 0; i < 1000; i++)
            {
                emp      = new Employee();
                emp.Name = "Name: " + i;
                int booo = rnd.Next(1);
                if (booo == 1)
                {
                    emp.IsMale = true;
                }
                else
                {
                    emp.IsMale = false;
                }
                //emp.PhoneNumber = rnd.Next(1231234, 3214321);
                emp.Age         = rnd.Next(18, 50);
                emp.DateofBirth = DateTime.Now;
                emp.Email       = "Something00" + i + "@infoSys.com";
                emp.State       = rnd.Next(1, 50);
                emp.State1      = db.States.First(p => p.StateID == emp.State);
                int edu = (rnd.Next(1, 7));
                emp.Educations.Add(db.Educations.Single(p => p.EducationID == edu));
                db.Employees.Add(emp);
            }
            db.SaveChanges();
        }
        public async Task <string> DeleteEmployee(int id)
        {
            List <Employees> EmployeeList;
            bool             isPresent = false;

            try
            {
                Employees employee = _context.Employees.Where(p => p.EmployeeId == id).FirstOrDefault();
                EmployeeList = await _context.Employees.Where(p => p.EmployeeId == id).ToListAsync();

                foreach (Employees emp in EmployeeList)
                {
                    if (employee.EmployeeId.Equals(id))
                    {
                        isPresent = true;
                        break;
                    }
                }
                if (isPresent)
                {
                    _context.Employees.Remove(employee);
                    _context.SaveChanges();
                    return("Employee Deleted Successfully");
                }
                else
                {
                    return("Employee Not Found");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #11
0
 public void Update(Employee employee)
 {
     using (EmployeeManagementContext db = new EmployeeManagementContext())
     {
         db.Employee.Update(employee);
         db.SaveChanges();
     }
 }
Пример #12
0
        public ActionResult DayOff([Bind(Include = "date")] DayOff dayOff)
        {
            List <DayOff> dayOffs = db.DayOffs.ToList();

            dayOff.date       = dayOffs[dayOffs.Count() - 1].date;
            dayOff.employeeId = userID;
            dayOff.status     = Models.DayOff.DayOffStatus.Pending;

            if (ModelState.IsValid)
            {
                db.DayOffs.Add(dayOff);
                db.SaveChanges();
                return(RedirectToAction("Request"));
            }
            ViewBag.name = staticName;
            return(View(dayOff));
        }
Пример #13
0
        public HttpResponseMessage Post([FromBody] StateModel value)
        {
            try
            {
                State sta = new State()
                {
                    Name = value.state
                };
                dbContext.States.Add(sta);
                dbContext.SaveChanges();

                return(Request.CreateResponse(HttpStatusCode.OK, true));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, false));
            }
        }
        public bool AddUpdateEmployee(Employee employee)
        {
            if (employee.Id != 0)
            {
                if (employee.Manager == null)
                {
                    employee.Manager = employee.Name;
                }

                db.Entry(employee).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
            else
            {
                db.Employees.Add(employee);
                return(db.SaveChanges() > 0);
            }
        }
Пример #15
0
        //Delete Record
        public void Delete(string EmpId)

        {
            using (EmployeeManagementContext db = new EmployeeManagementContext())
            {
                Employee e = db.Employee.Find(EmpId);
                db.Employee.Remove(e);
                db.SaveChanges();
            }
        }
Пример #16
0
        public void Should_Be_Able_To_Retrieve_Employee_From_DB()
        {
            using (var context = new EmployeeManagementContext())
                using (var repo = new EmployeeRepository(context))
                    using (var txn = context.Database.BeginTransaction())
                    {
                        context.Set <EmployeeEntity>().AddRange(Data.EmployeeEntities);
                        context.SaveChanges();

                        var employee = repo.GetEmployee(Data.User1Id);

                        txn.Rollback();

                        Assert.IsNotNull(employee);
                    }
        }
Пример #17
0
        public void Should_Be_Able_To_Retrieve_All_Employees_From_DB()
        {
            using (var context = new EmployeeManagementContext())
                using (var repo = new EmployeeRepository(context))
                    using (var txn = context.Database.BeginTransaction())
                    {
                        context.Set <EmployeeEntity>().AddRange(Data.EmployeeEntities);
                        context.SaveChanges();

                        var employees = repo.GetAllEmployees();

                        txn.Rollback();

                        Assert.AreEqual(2, employees.Count);
                    }
        }
Пример #18
0
        public ActionResult EditDetails([Bind(Include = "dob,phoneNo,homeAddress,username,password")] Employee employee)
        {
            employee.username = userID;
            int n = int.Parse(employee.phoneNo.ToString());

            employee.phoneNo = n;
            if (ModelState.IsValid)
            {
                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.id   = userID;
            ViewBag.name = staticName;
            return(View(employee));
        }
Пример #19
0
        public ActionResult Registration(RegistrationView registrationView)
        {
            bool   statusRegistration  = false;
            string messageRegistration = string.Empty;

            if (ModelState.IsValid)
            {
                // Email Verification
                string userName = Membership.GetUserNameByEmail(registrationView.Email);
                if (!string.IsNullOrEmpty(userName))
                {
                    ModelState.AddModelError("Warning Email", "Sorry: Email already Exists");
                    return(View(registrationView));
                }

                //Save User Data
                using (EmployeeManagementContext dbContext = new EmployeeManagementContext())
                {
                    var user = new User()
                    {
                        Username       = registrationView.Username,
                        FirstName      = registrationView.FirstName,
                        LastName       = registrationView.LastName,
                        Email          = registrationView.Email,
                        Password       = registrationView.Password,
                        IsActive       = true,
                        ActivationCode = Guid.NewGuid(),
                    };

                    dbContext.Users.Add(user);
                    dbContext.SaveChanges();
                }

                //Verification Email
                //VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString());
                messageRegistration = "Your account has been created successfully.";
                statusRegistration  = true;
            }
            else
            {
                messageRegistration = "Something Wrong!";
            }
            ViewBag.Message = messageRegistration;
            ViewBag.Status  = statusRegistration;

            return(View(registrationView));
        }
 public ActionResult Create(Employee employee)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             db.EmployeeDbSet.Add(employee);
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Пример #21
0
        public ActionResult ActivationAccount(string id)
        {
            bool statusAccount = false;

            using (EmployeeManagementContext dbContext = new EmployeeManagementContext())
            {
                var userAccount = dbContext.Users.Where(u => u.ActivationCode.ToString().Equals(id)).FirstOrDefault();

                if (userAccount != null)
                {
                    userAccount.IsActive = true;
                    dbContext.SaveChanges();
                    statusAccount = true;
                }
                else
                {
                    ViewBag.Message = "Something Wrong !!";
                }
            }
            ViewBag.Status = statusAccount;
            return(View());
        }
Пример #22
0
 public void Create(Position position)
 {
     context.Positions.Add(position);
     context.SaveChanges();
 }
Пример #23
0
 public void Create(CareerHistory value)
 {
     context.Careers.Add(value);
     context.SaveChanges();
 }
Пример #24
0
 public void Create(Employee employee)
 {
     context.Employees.Add(employee);
     context.SaveChanges();
 }
Пример #25
0
 public void Save()
 {
     context.SaveChanges();
 }
Пример #26
0
 public void Save()
 {
     _ctx.SaveChanges();
 }