コード例 #1
0
        public async Task <UserViewModel> Register(UserViewModel userViewModel)
        {
            try
            {
                User UserObj = new User()
                {
                    FirstName          = userViewModel.PersonName.FirstName,
                    LastName           = userViewModel.PersonName.LastName,
                    UserName           = userViewModel.Email,
                    Password           = userViewModel.Password,
                    Email              = userViewModel.Email,
                    Mobile             = userViewModel.Mobile,
                    DateOfBirth        = userViewModel.DateOfBirth,
                    Gender             = userViewModel.Gender,
                    CountryID          = userViewModel.CountryID,
                    ReceiveNewsLetters = userViewModel.ReceiveNewsLetters,
                    RoleId             = 2
                };

                _dbContext.Add(UserObj);



                await _dbContext.SaveChangesAsync();

                foreach (var item in userViewModel.Skills)
                {
                    Skill SkillObj = new Skill()
                    {
                        SkillName  = item.SkillName,
                        SkillLevel = item.SkillName,
                        Id         = UserObj.Id
                    };

                    _dbContext.Skills.Add(SkillObj);
                    await _dbContext.SaveChangesAsync();
                }

                UserViewModel Obj = new UserViewModel()
                {
                    Id         = UserObj.Id,
                    PersonName = new PersonName {
                        FirstName = UserObj.FirstName, LastName = UserObj.LastName
                    },
                    Email    = UserObj.Email,
                    UserName = UserObj.UserName,
                    RoleId   = UserObj.RoleId
                };

                return(Obj);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #2
0
        public async Task <ResponseViewModel> AddProject(ProjectViewModel project)
        {
            try
            {
                ResponseViewModel ResObj  = new ResponseViewModel();
                Project           ProjObj = new Project()
                {
                    ProjectName      = project.ProjectName,
                    TeamSize         = project.TeamSize,
                    DateOfStart      = project.DateOfStart,
                    Active           = project.Active,
                    ClientLocationID = project.ClientLocationID,
                    Status           = project.Status
                };



                _dbContext.Add(ProjObj);
                await _dbContext.SaveChangesAsync();

                ProjectViewModel ProjDispObj = new ProjectViewModel()
                {
                    ProjectId        = ProjObj.ProjectId,
                    ProjectName      = ProjObj.ProjectName,
                    TeamSize         = ProjObj.TeamSize,
                    DateOfStart      = ProjObj.DateOfStart,
                    Active           = ProjObj.Active,
                    ClientLocationID = ProjObj.ClientLocationID,
                    ClientLocation   = _dbContext.ClientLocations.Where(x => x.ClientLocationID == ProjObj.ClientLocationID).FirstOrDefault(),
                    Status           = ProjObj.Status
                };

                ResObj.Result  = ProjDispObj;
                ResObj.Status  = true;
                ResObj.Messege = "Project has been added successfully !";

                return(ResObj);
            }
            catch (Exception ex)
            {
                ResponseViewModel ResObj = new ResponseViewModel()
                {
                    Status  = false,
                    Messege = "Something Went Wrong !",
                    Result  = ex
                };

                return(ResObj);
            }
        }