Example #1
0
        public IHttpActionResult AddEmployee(CEmployee employee)
        {
            try
            {
                string FolderPath = System.Web.HttpContext.Current.Server.MapPath("~/ProfileImage");

                if (!System.IO.Directory.Exists(FolderPath))
                {
                    System.IO.Directory.CreateDirectory(FolderPath);
                }

                string ImageName = employee.Image;
                string ImagePath = System.IO.Path.Combine(FolderPath, ImageName);

                byte[] ImageByte = Convert.FromBase64String(employee.ImageBase64.Split(',')[1]);
                System.IO.File.WriteAllBytes(ImagePath, ImageByte);

                string IPath        = "~/ProfileImage";
                string relativepath = IPath + "/" + ImageName;


                Employee Emp = new Employee();
                Emp.UserId       = employee.UserId;
                Emp.FirstName    = employee.FirstName;
                Emp.MiddelName   = employee.MiddelName;
                Emp.LastName     = employee.LastName;
                Emp.BirthDate    = employee.BirthDate.Value.ToLocalTime();
                Emp.Gender       = employee.Gender;
                Emp.Designation  = employee.Designation;
                Emp.Image        = relativepath;
                Emp.Role         = employee.Role;
                Emp.Department   = employee.Department;
                Emp.JoinDate     = employee.JoinDate.Value.ToLocalTime();
                Emp.Email        = employee.Email;
                Emp.Password     = employee.Password;
                Emp.Address      = employee.Address;
                Emp.Skill        = employee.Skill;
                Emp.Mobile       = employee.Mobile;
                Emp.Description  = employee.Description;
                Emp.Country      = employee.Country;
                Emp.State        = employee.State;
                Emp.City         = employee.City;
                Emp.ZipCode      = employee.ZipCode;
                Emp.Relationship = employee.Relationship;

                EmployeeObj.InsertModel(Emp);
                EmployeeObj.Save();

                if (true)
                {
                    return(Ok("Employee Insert Successfully"));
                }
            }
            catch (Exception ex)
            {
                var error = ex.Message;
                return(null);
            }
        }
Example #2
0
 public IHttpActionResult AddSkills(CSkill Skill)
 {
     try
     {
         Skill Sk = new Skill();
         Sk.SkillName = Skill.SkillName;
         skillObj.InsertModel(Sk);
         skillObj.Save();
         if (true)
         {
             return(Ok("Skill Insert Successfully"));
         }
     }
     catch (Exception ex)
     {
         var error = ex.Message;
         return(null);
     }
 }
        public async Task <IHttpActionResult> Register(CRegisterUser model)

        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            IdentityResult result;

            using (var context = new ApplicationDbContext())
            {
                var user = new ApplicationUser()
                {
                    UserName = model.Email, Email = model.Email
                };

                result = await UserManager.CreateAsync(user, model.Password);

                //var roleStore = new RoleStore<IdentityRole>(context);
                //var roleManager = new RoleManager<IdentityRole>(roleStore);
                //await roleManager.CreateAsync(new IdentityRole { Name = model.Role });

                //var userStore = new UserStore<ApplicationUser>(context);
                //var userManager = new UserManager<ApplicationUser>(userStore);

                //await userManager.AddToRoleAsync(user.Id, model.Role);

                var Folderpath = System.Web.HttpContext.Current.Server.MapPath("~/Image");

                if (!System.IO.Directory.Exists(Folderpath))
                {
                    System.IO.Directory.CreateDirectory(Folderpath);
                }

                RegisterUser RUser = new RegisterUser();
                RUser.UserId          = user.Id;
                RUser.FirstName       = model.FirstName;
                RUser.MiddelName      = model.MiddelName;
                RUser.LastName        = model.LastName;
                RUser.Email           = model.Email;
                RUser.Phone           = model.Phone;
                RUser.Password        = model.Password;
                RUser.ConfirmPassword = model.ConfirmPassword;
                RUser.Role            = model.Role;

                var    ImagePath  = Path.Combine(Folderpath, model.Image);
                byte[] imageBytes = Convert.FromBase64String(model.ImageBase64.Split(',')[1]);
                File.WriteAllBytes(ImagePath, imageBytes);

                string path         = "~/Image";
                string relativepath = path + "/" + model.Image;
                RUser.Image = relativepath;
                interfaceObj.InsertModel(RUser);
                interfaceObj.Save();
            }
            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok("User Register"));
        }