/// <summary> /// update image information of project /// </summary> /// <param name="projectId">project id</param> /// <param name="image">image id</param> /// <param name="isCoverImage">is cover image of project or not</param> /// <param name="listImages">list images of project returned</param> /// <returns></returns> public bool UpdateProjectImage(int projectId, MessageModel.UpdateProjectImage imageInfor, bool isCoverImage) { try { share_Images image = imageRepository.GetByID(imageInfor.ImageId); image.ImageName = imageInfor.Name; image.Status = imageInfor.IsActive ? (int)Define.Status.Active : (int)Define.Status.Deactive; portal_Projects project = db.GetProjectById(projectId); if (isCoverImage) { project.CoverImage = image; } else { if (project.CoverImageId == image.Id) { project.CoverImage = null; } } imageRepository.Update(image); db.Update(project); db.Save(); imageRepository.Save(); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Update project /// </summary> /// <param name="project"></param> /// <returns></returns> public bool UpdateProject(Model.ViewModel.ProjectFullView projectViewModel) { portal_Projects project = db.GetProjectById(projectViewModel.Id); if (project == null) { return(false); } else { project.Name = projectViewModel.Name; project.Region = projectViewModel.Region; project.Address = projectViewModel.Address; project.Investor = projectViewModel.Investor; project.ProjectPackage = projectViewModel.ProjectPackage; project.TotalInvestment = projectViewModel.TotalInvestment; project.Duration = projectViewModel.Duration; project.ProgressStatus = projectViewModel.ProgressStatus; project.Type = projectViewModel.Type; project.SortOrder = projectViewModel.SortOrder; project.Status = projectViewModel.Status; project.Description = projectViewModel.Description; project.Description2 = projectViewModel.Description2; db.Save(); return(true); } }
/// <summary> /// Add new project to database /// </summary> /// <returns></returns> public bool AddProject(MessageModel.CreateProjectPostRequest newProject) { try { portal_Projects project = new portal_Projects() { Name = newProject.Name, Region = newProject.Region, Address = newProject.Address, Investor = newProject.Investor, ProjectPackage = newProject.ProjectPackage, TotalInvestment = newProject.TotalInvestment, Duration = newProject.Duration, ProgressStatus = newProject.ProgressStatus, Type = newProject.Type, CoverImageId = newProject.CoverImageId, SortOrder = newProject.SortOrder, Status = newProject.Status, Description = newProject.Description, Description2 = newProject.Description2 }; share_Images coverImage = imageRepository.GetByID(newProject.CoverImageId); project.share_Images.Add(coverImage); db.Insert(project); db.Save(); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Get information of project and return Edit View for user update data for project /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } portal_Projects project = service.GetProjectById((int)id); if (project == null) { return(HttpNotFound()); } // Populate status dropdownlist if (project.Status != null) { var status = (Define.Status)project.Status; PopulateStatusDropDownList(status); } else { PopulateStatusDropDownList(); } // Populate project type dropdownlist PopulateProjectTypeDropDownList((Define.ProjectType)project.Type); // Populate region dropdownlist PopulateRegionDropDownList((Define.Region)project.Region); // Populate progress status dropdownlist PopulateProgressStatusDropDownList((Define.ProgressStatus)project.ProgressStatus); return(View(project.ConvertToProjectFullView())); }
/// <summary> /// Create list product image for return to client side /// </summary> /// <param name="productId"></param> /// <returns></returns> public ActionResult ListImageProject(int projectId) { portal_Projects project = service.GetProjectById(projectId); ListImageProjectPartialViewModels listImageViewModels = new ListImageProjectPartialViewModels() { ProjectId = projectId, Images = project.share_Images.ConvertToImageProjectViewModels(), CoverImageId = project.CoverImageId }; return(PartialView("ListImageProject", listImageViewModels)); }
/// <summary> /// Delete project (set Status is Delete) /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteProject(int id) { try { portal_Projects project = GetProjectById(id); project.Status = (int)Define.Status.Delete; db.Save(); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Set as cover image of project /// </summary> /// <param name="projectId"></param> /// <param name="imageId"></param> /// <param name="listImages"></param> /// <returns></returns> public bool SetAsCoverImage(int projectId, int imageId) { try { portal_Projects project = GetProjectById(projectId); project.CoverImageId = imageId; db.Update(project); db.Save(); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Add image for exist project /// </summary> /// <param name="ProjectId">project id</param> /// <param name="photo">new image</param> /// <param name="listImages"> return list image after adding finish</param> /// <returns>return true if action is success or false action is fail</returns> public bool AddImageForProject(int projectId, Model.Context.share_Images photo) { portal_Projects project = db.GetProjectById(projectId); if (project == null) { return(false); } else { project.share_Images.Add(photo); db.Save(); return(true); } }
public ActionResult ProjectDetails(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } portal_Projects response = service.GetDetailProject(id); ViewBag.ProjectType = EnumHelper.GetDescriptionFromEnum((Define.ProjectType)response.Type); ViewBag.Region = EnumHelper.GetDescriptionFromEnum((Define.Region)response.Region); ViewBag.ProgressStatus = EnumHelper.GetDescriptionFromEnum((Define.ProgressStatus)response.ProgressStatus); ViewBag.RelatedProjects = service.GetRelatedProject(id); return(View("ProjectDetails", response)); }
/// <summary> /// Delete image in project /// </summary> /// <param name="projectId">project id</param> /// <param name="imageId">id of image need to delete</param> /// <param name="listImages">list images of project after do action</param> /// <param name="imagePath">path of deteled image(using for delete image in folder)</param> /// <returns>return true if action is success or false if action is fail</returns> public bool DeleteImage(int projectId, int imageId, out Model.Context.share_Images deleteImages) { try { portal_Projects project = GetProjectById(projectId); share_Images image = project.share_Images.Where(i => i.Id == imageId).SingleOrDefault(); deleteImages = image; //Delete image in product project.share_Images.Remove(image); db.Save(); // Delete image in table share_images var deleteImage = imageRepository.GetByID(imageId); imageRepository.Delete(deleteImage); imageRepository.Save(); return(true); } catch (Exception) { deleteImages = null; return(false); } }
public static ProjectFullView ConvertToProjectFullView(this portal_Projects project) { ProjectFullView projectFullView = new ProjectFullView() { Id = project.Id, Name = project.Name, Region = project.Region, Address = project.Address, Investor = project.Investor, ProjectPackage = project.ProjectPackage, CoverImageId = project.CoverImageId, TotalInvestment = project.TotalInvestment, Duration = project.Duration, ProgressStatus = project.ProgressStatus, Type = project.Type, SortOrder = project.SortOrder, Status = project.Status, Description = project.Description, Description2 = project.Description2, share_Images = project.share_Images.ConvertToImageProjectViewModels() }; return(projectFullView); }