Пример #1
0
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.ID)
            {
                return(BadRequest());
            }

            db.Entry(employee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create([Bind(Include = "ID,Forename,Surname,JobTitle,EmployeeNumber,File")] Employee employee, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    byte[] thePictureAsBytes = new byte[file.ContentLength];
                    using (BinaryReader theReader = new BinaryReader(file.InputStream))
                    {
                        thePictureAsBytes = theReader.ReadBytes(file.ContentLength);
                    }


                    // Convert photo to base64
                    string tempPhoto = Convert.ToBase64String(thePictureAsBytes);

                    // Send thePictureAsBytes to Google Vision API
                    bool imageValidated = ImageValidationHelper.ValidateImage(tempPhoto);

                    // Check if photo meets standard
                    if (imageValidated)
                    {
                        // add photo to employee
                        employee.Photo = tempPhoto;
                    }
                }


                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,PhoneNumber")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "ID,Name,Address")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Gender,Salary")] employees_tbl employees_tbl)
        {
            if (ModelState.IsValid)
            {
                db.employees_tbl.Add(employees_tbl);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employees_tbl));
        }
Пример #6
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] SkillDto skillDto)
        {
            if (ModelState.IsValid)
            {
                db.Skills.Add(new Skill()
                {
                    Description = skillDto.Description, Name = skillDto.Name
                });
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(skillDto));
        }
Пример #7
0
 public ActionResult Create(Employee emp)
 {
     try
     {
         using (EmployeeDataModel context = new EmployeeDataModel())
         {
             context.Employees.Add(emp);
             context.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Пример #8
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         using (EmployeeDataModel context = new EmployeeDataModel())
         {
             var employee = context.Employees.Single(m => m.ID == id);
             if (TryUpdateModel(employee))
             {
                 //To Do:- database code
                 context.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             return(View(employee));
         }
     }
     catch
     {
         return(View());
     }
 }
 public void SaveChanges()
 {
     entities.SaveChanges();
 }
 public bool Save()
 {
     _context.SaveChanges();
     return(true);
 }
        public ActionResult Create(ViewModel.EmployeeSkillDto employeeSkillDto, string submit)
        {
            List <SelectListItem> skills = new List <SelectListItem>();

            foreach (var dbSkill in db.Skills)
            {
                skills.Add(new SelectListItem()
                {
                    Text = dbSkill.Name, Value = dbSkill.Id.ToString()
                });
            }

            ViewBag.SkillId = new SelectList(skills, "Value", "Text");


            switch (submit)
            {
            case "Cancel":
                return(RedirectToAction("Index"));

            case "AddMoreSkill":

                employeeSkillDto.Skilllist.Add(new SkillDto());

                return(View(employeeSkillDto));

            case "Create":
                if (ModelState.IsValid)
                {
                    var newEmployee = new Employee()
                    {
                        FirstName   = employeeSkillDto.FirstName,
                        LastName    = employeeSkillDto.LastName,
                        PhoneNumber = employeeSkillDto.PhoneNumber
                    };

                    db.Employees.Add(newEmployee);
                    db.SaveChanges();

                    var selectNewEmplyee =
                        db.Employees.FirstOrDefault(e => e.FirstName == employeeSkillDto.FirstName &&
                                                    e.LastName == employeeSkillDto.LastName);

                    foreach (var empSkill in employeeSkillDto.Skilllist)
                    {
                        var newEmpSkill = new EmployeeSkill()
                        {
                            Employee        = selectNewEmplyee,
                            EmployeeId      = selectNewEmplyee.Id,
                            SkillId         = empSkill.Id,
                            YearsExperience = empSkill.YearExprience
                        };
                        db.EmployeeSkills.Add(newEmpSkill);
                        db.SaveChanges();
                    }

                    return(RedirectToAction("Index"));
                }

                ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "FirstName", employeeSkillDto.EmployeeId);
                return(View(employeeSkillDto));

            default:
                int index      = Convert.ToInt32(submit);
                var removeItem = employeeSkillDto.Skilllist[index];
                if (employeeSkillDto.Skilllist.Count > 1)
                {
                    employeeSkillDto.Skilllist.Remove(removeItem);
                }
                return(View(employeeSkillDto));
            }
        }