public bool CreateBidRequest(CreateBidRequestViewModel requestModel)
        {
            var dev     = freelancerDb.Developers.FirstOrDefault(t => t.DeveloperId == requestModel.DeveloperId);
            var project = freelancerDb.Projects.FirstOrDefault(t => t.ProjectId == requestModel.ProjectId);

            if (dev == null || project == null)
            {
                return(false);
            }

            var isExist = freelancerDb.BidRequests.Any(t => t.Developer.DeveloperId == requestModel.DeveloperId && t.Project.ProjectId == requestModel.ProjectId);

            if (isExist)
            {
                return(false);
            }

            var bidRequest = new BidRequest
            {
                BidRequestId  = Guid.NewGuid().ToString(),
                CreationDate  = DateTime.Now,
                Developer     = dev,
                Project       = project,
                Note          = requestModel.Note,
                Price         = Convert.ToDouble(requestModel.Price),
                DaysToFinish  = requestModel.DaysToFinish,
                RequestStatus = RequestStatus.Pending
            };

            freelancerDb.BidRequests.Add(bidRequest);
            freelancerDb.SaveChanges();
            return(true);
        }
Esempio n. 2
0
        public bool AddProject(string userId, AddProjectViewModel project)
        {
            var owner = freelancerDb.Owners.FirstOrDefault(t => t.User.Id == userId);

            if (owner == null)
            {
                return(false);
            }

            var requiredSkills = GetSkillsBySkillNames(project.RequiredSkill);

            var newProject = new Project
            {
                ProjectId   = Guid.NewGuid().ToString(),
                Owner       = owner,
                Description = project.Description,
                Title       = project.Title,
                MaxPrice    = double.Parse(project.MaxPrice),
                MinPrice    = double.Parse(project.MinPrice),
                Status      = Status.Pending
            };

            newProject.ProjectSkill = AddProjectSkillsBySkills(requiredSkills, newProject);

            freelancerDb.Projects.Add(newProject);
            freelancerDb.SaveChanges();
            return(true);
        }
Esempio n. 3
0
        public string AddRandomProject()
        {
            var faker = new Bogus.Faker();

            var user = new User
            {
                Id             = Guid.NewGuid().ToString(),
                UserName       = faker.Person.UserName,
                Email          = faker.Person.Email,
                Name           = faker.Person.FirstName,
                Surname        = faker.Person.LastName,
                ProfilePicture = faker.Person.Avatar,
                Country        = faker.Address.Country()
            };

            var project = new Project
            {
                ProjectId = Guid.NewGuid().ToString(),
                Owner     = new Owner {
                    OwnerId = Guid.NewGuid().ToString(), User = user
                },
                Title       = faker.Name.JobTitle(),
                Description = faker.Company.CatchPhrase(),
                MinPrice    = faker.Random.Int(1, 100),
                MaxPrice    = faker.Random.Int(100, 10000),
                Status      = Status.Pending
                              //RequiredSkill = new Skill { SkillId = Guid.NewGuid().ToString(), Name = faker.Name.JobType() }
            };

            project.ProjectSkill = new List <ProjectSkill>
            {
                new ProjectSkill
                {
                    ProjectSkillId = Guid.NewGuid().ToString(),
                    Skill          = new Skill
                    {
                        SkillId = Guid.NewGuid().ToString(),
                        Name    = faker.Company.CompanySuffix()
                    },
                    Project = project
                },
                new ProjectSkill
                {
                    ProjectSkillId = Guid.NewGuid().ToString(),
                    Skill          = new Skill
                    {
                        SkillId = Guid.NewGuid().ToString(),
                        Name    = faker.Company.CompanySuffix()
                    },
                    Project = project
                },
                new ProjectSkill
                {
                    ProjectSkillId = Guid.NewGuid().ToString(),
                    Skill          = new Skill
                    {
                        SkillId = Guid.NewGuid().ToString(),
                        Name    = faker.Company.CompanySuffix()
                    },
                    Project = project
                }
            };

            freelancerDb.Projects.Add(project);
            freelancerDb.SaveChanges();
            return("Added");
        }