public Result <PostAProject> Save(PostAProject PostAProject) { var result = new Result <PostAProject>(); try { var objtosave = _context.postAProjects.FirstOrDefault(u => u.PostId == PostAProject.PostId); if (objtosave == null) { objtosave = new PostAProject(); _context.postAProjects.Add(objtosave); } objtosave.WUserId = PostAProject.WUserId; objtosave.ProjectName = PostAProject.ProjectName; objtosave.Price = PostAProject.Price; objtosave.StartTime = PostAProject.StartTime; objtosave.EndTime = PostAProject.EndTime; objtosave.Description = PostAProject.Description; objtosave.Members = PostAProject.Members; if (!IsValid(objtosave, result)) { return(result); } _context.SaveChanges(); } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
public PostAProject Insert(PostProjectModel postProjectModel) { var postAProject = new PostAProject(); postAProject.WUserId = HttpUtil.CurrentUser.UserId; postAProject.ProjectName = postProjectModel.ProjectName; postAProject.Description = postProjectModel.Description; postAProject.Price = postProjectModel.Price; postAProject.StartTime = postProjectModel.StartTime; postAProject.EndTime = postProjectModel.EndTime; postAProject.Members = postProjectModel.Members; return(postAProject); }
public bool IsValid(PostAProject obj, Result <PostAProject> result) { if (!ValidationHelper.IsStringValid(obj.WUserId.ToString())) { result.HasError = true; result.Message = "Invalid WUserId"; return(false); } if (!ValidationHelper.IsStringValid(obj.ProjectName)) { result.HasError = true; result.Message = "Invalid ProjectName"; return(false); } if (!ValidationHelper.IsStringValid(obj.Price.ToString())) { result.HasError = true; result.Message = "Invalid Price"; return(false); } if (!ValidationHelper.IsStringValid(obj.StartTime.ToString())) { result.HasError = true; result.Message = "Invalid StartTime"; return(false); } if (!ValidationHelper.IsStringValid(obj.EndTime.ToString())) { result.HasError = true; result.Message = "Invalid EndTime"; return(false); } if (!ValidationHelper.IsStringValid(obj.Description)) { result.HasError = true; result.Message = "Invalid Description"; return(false); } if (!ValidationHelper.IsStringValid(obj.Members.ToString())) { result.HasError = true; result.Message = "Invalid Members"; return(false); } return(true); }
private bool IsValidToSave(PostAProject obj, Result <PostAProject> result) { if (!ValidationHelper.IsIntValid(obj.PostId.ToString())) { result.HasError = true; result.Message = "Invalid UserID"; return(false); } if (_context.postAProjects.Any(u => u.PostId == obj.PostId)) { result.HasError = true; result.Message = "Email PostId"; return(false); } return(true); }
public ActionResult CreateProject(PostProjectModel PostProjectModel) { if (!ModelState.IsValid) { return(View("CreateProject", PostProjectModel)); } try { var postAProject = new PostAProject(); postAProject.ProjectName = PostProjectModel.ProjectName; postAProject.Description = PostProjectModel.Description; postAProject.Price = PostProjectModel.Price; postAProject.StartTime = PostProjectModel.StartTime; postAProject.EndTime = PostProjectModel.EndTime; postAProject.Members = PostProjectModel.Members; var result = postProjectDao.Save(postAProject); foreach (var x in PostProjectModel.SectionName) { var projectsection = new ProjectSection(); projectsection.SectionName = x; var result1 = projectSectionDao.Save(projectsection); } foreach (var skillid in PostProjectModel.SkillId) { var projectskill = new ProjectSkills(); projectskill.SkillID = skillid; var result2 = projectSkillDao.Save(projectskill); } if (result.HasError) { ViewBag.Message = result.Message; return(View("CreateProject", PostProjectModel)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(RedirectToAction("CreateProject")); }
public PostProjectModel creation(PostAProject result, List <ProjectSkills> skills, List <Skill> Allskills) { var postModel = new PostProjectModel(); postModel.PostId = result.PostId; postModel.Description = result.Description; postModel.EndTime = result.EndTime; postModel.StartTime = result.StartTime; postModel.Members = result.Members; postModel.Price = result.Price; postModel.ProjectName = result.ProjectName; var skillStr = skills.Select(m => m.SkillName).ToList(); string str = ""; int c = 0; foreach (var v in skillStr) { if (c != 0) { str = str + "," + v; } else { str = v; c++; } } List <string> Skills = new List <string>(); foreach (var v in Allskills) { if (!str.Contains(v.SkillName)) { Skills.Add(v.SkillName); } } postModel.SkillName = Skills; postModel.Selectskills = str; return(postModel); }