Пример #1
0
 private static void ValidateImage(WebApplication2.APIModel.Employee employee)
 {
     if (!HelperFunctions.IsBase64String(employee.ProfileImage))
     {
         throw new ValidationException("Invalid Image,Please provide valid Base64 string of image.");
     }
 }
Пример #2
0
 public void ValidateEmployee(WebApplication2.APIModel.Employee employee)
 {
     ValidateName(employee.Name);
     ValidateAge(employee.Age);
     ValidateGender(employee.Gender);
     ValidateSalary(employee.Salary);
     ValidateAddress(employee.Address);
     ValidateImage(employee);
 }
Пример #3
0
        public string Add(WebApplication2.APIModel.Employee employee)
        {
            ValidateEmployee(employee);
            var emp = new Employee
            {
                Name         = employee.Name,
                Address      = employee.Address,
                Gender       = employee.Gender,
                Age          = employee.Age,
                Salary       = employee.Salary,
                WorkContact  = employee.Telephone.WorkContact,
                Mobile       = employee.Telephone.Mobile,
                ProfileImage = employee.ProfileImage
            };

            db.Employees.Add(emp);
            db.SaveChanges();
            return("Employee Id:" + emp.Id);
        }
Пример #4
0
        public WebApplication2.APIModel.Employee Update(WebApplication2.APIModel.Employee employee)
        {
            ValidateEmployee(employee);
            var emp = db.Employees.Where(t => t.Id == employee.Id).FirstOrDefault();

            if (emp != null)
            {
                emp.Name         = employee.Name;
                emp.Address      = employee.Address;
                emp.Gender       = employee.Gender;
                emp.Age          = employee.Age;
                emp.Salary       = employee.Salary;
                emp.WorkContact  = employee.Telephone.WorkContact;
                emp.Mobile       = employee.Telephone.Mobile;
                emp.ProfileImage = employee.ProfileImage;

                db.SaveChanges();

                return(db.Employees.Where(t => t.Id == emp.Id).Select(t => new WebApplication2.APIModel.Employee
                {
                    Id = t.Id,
                    Name = t.Name,
                    Address = t.Address,
                    Gender = t.Gender,
                    Age = t.Age,
                    Salary = t.Salary,
                    ProfileImage = t.ProfileImage,
                    Telephone = new Telephone
                    {
                        WorkContact = t.WorkContact,
                        Mobile = t.Mobile
                    }
                }).FirstOrDefault());
            }
            return(null);
        }