public ActionResult Edit([Bind(Include = "ID,CategoryID,ProjectID")] ProjectCategory projectCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(projectCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Name", projectCategory.CategoryID);
     ViewBag.ProjectID  = new SelectList(db.Projects, "ID", "Name", projectCategory.ProjectID);
     return(View(projectCategory));
 }
Пример #2
0
        public async void handle_CreateProjectCategoryResultlNull_test()
        {
            Project             returnn = new Project();
            OrganisationProject op      = new OrganisationProject();
            ProjectCategory     pc      = null;

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Update(It.IsAny <Project>())).Returns(returnn);
            this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.DeleteProjectOrganisation(It.IsAny <int>()))
            .Returns(true);
            this._unitOfUnitMock.Setup(mock =>
                                       mock.RelationsRepository.CreateOrganisationProject(It.IsAny <OrganisationProject>())).Returns(op);
            this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.DeleteCategoriesProject(It.IsAny <int>()))
            .Returns(true);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectCategory(It.IsAny <ProjectCategory>())).Returns(pc);

            UpdateProjectCommand command = new UpdateProjectCommand(new CreateProjectModel()
            {
                ProjectName = "test",
                Categories  = new List <Category>()
                {
                    new Category()
                    {
                        CategoryId = 1, CategoryName = "test", Created = DateTime.Now, Id = 1
                    }
                },
                ResearcherCategories = new List <ResearcherCategory>()
                {
                    new ResearcherCategory()
                    {
                        Researcher = new Researcher()
                        {
                            Id = 1
                        }, Category = new Category()
                        {
                            Id = 1
                        }
                    }
                },
                Organisations = new List <Organisation>()
                {
                    new Organisation()
                    {
                        Id = 1,
                    }
                }
            });
            UpdateProjectHandler handler = new UpdateProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.False((bool)result);
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "ProjectCategoryID,ProjectCategory1,EnableProjectCategory,DateModified,CreatedBy,DateCreated")] ProjectCategory projectCategory)
        {
            if (ModelState.IsValid)
            {
                projectCategory.ProjectCategoryID = Guid.NewGuid();
                db.ProjectCategory.Add(projectCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(projectCategory));
        }
Пример #4
0
        public ActionResult Delete(int?id)
        {
            ProjectCategory category = _db.ProjectCategories.Find(id);

            if (category == null)
            {
                return(HttpNotFound());
            }

            _db.ProjectCategories.Remove(category);
            _db.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
Пример #5
0
 public ActionResult EditCategory(ProjectCategory cat)
 {
     if (ModelState.IsValid)
     {
         // Repository.CreateProjectCategory(cat);
         Repository.EditProjectCategory(cat);
         return(PartialView("ProjectCategoryPartialViews/_CategorySuccess"));
     }
     else
     {
         return(PartialView("ProjectCategoryPartialViews/_EditCategory", cat));
     }
 }
        public ActionResult Create([Bind(Include = "Id,ProjectId,CategoryId")] ProjectCategory projectCategory)
        {
            if (ModelState.IsValid)
            {
                db.ProjectCategories.Add(projectCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", projectCategory.CategoryId);
            ViewBag.ProjectId  = new SelectList(db.Projects, "Id", "Name", projectCategory.ProjectId);
            return(View(projectCategory));
        }
Пример #7
0
        public async Task <int> CreateAsync(ProjectCategoryDto projectCategoryDto)
        {
            var projectCategory = new ProjectCategory
            {
                Title       = projectCategoryDto.ShortDescription,
                Description = projectCategoryDto.Description
            };

            _dataContext.ProjectCategories.Add(projectCategory);
            await _dataContext.SaveChangesAsync();

            return(projectCategory.Id);
        }
Пример #8
0
        public ProjectCategory SetCategory(ProjectCategory projectCategory)
        {
            try
            {
                _projectCategoryRepository.InsertOrUpdateProjectCategory(projectCategory);

                return(projectCategory);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #9
0
        private void addCategoryAndPropertyToProject(Project prj, ProjectCategory newCat, string propName, string propDesc, string propValue)
        {
            ///add to pipingProject, the PnPProject under piping.dcf
            bool added = prj.AddProjectCategory(newCat);

            if (added)
            {
                ProjectProperty pp = new ProjectProperty(newCat.Name, propName, propDesc, propDesc);
                prj.AddProjectProperty(pp);
                ///above created a "DBInfo_DBInstance" column in PnPProject table under piping.dcf
                prj.SetProjectPropertyValue(pp, propValue);
            }
        }
Пример #10
0
        public ProjectCategory Get(string id)
        {
            ProjectCategory category = _context.ProjectCategories.FirstOrDefault(
                x => x.Id.Equals(id)
                );

            if (category == null)
            {
                string msg = $"ProjectCategory not found: {id}";
                throw new NotFoundInDBException(msg);
            }

            return(category);
        }
Пример #11
0
        public ProjectCategory CopyFrom(string newName, ProjectCategory other)
        {
            var newProjectCategory = _Create(newName);
            var activeTemplates    = other.QuestionTemplates.Where(qt => qt.Status == Status.Active);

            foreach (var template in activeTemplates)
            {
                newProjectCategory.QuestionTemplates.Add(template);
            }

            _context.ProjectCategories.Add(newProjectCategory);
            _context.SaveChanges();
            return(newProjectCategory);
        }
        /// <summary>
        /// Recursively sorts categories
        /// </summary>
        /// <param name="InReportSettings">Settings</param>
        /// <param name="InCategory">Category to sort (along with all child categories)</param>
        static void SortCategoriesRecursively(ReportSettings InReportSettings, ProjectCategory InCategory)
        {
            // Sort categories by name alphabetically.
            InCategory.Subcategories.Sort(new CategorySortComparer());

            // Sort changes by their type of change (new -> changed -> fix), then alphabetically
            InCategory.Changes.Sort(new ChangeSortComparer());

            // Recurse!
            foreach (var CurSubcategory in InCategory.Subcategories)
            {
                SortCategoriesRecursively(InReportSettings, CurSubcategory);
            }
        }
        // GET: ProjectCategories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProjectCategory projectCategory = db.ProjectCategories.Find(id);

            if (projectCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(projectCategory));
        }
Пример #14
0
        public async Task ChangePositionAsync(List <ProjectCategoryViewModel> listVM)
        {
            int count = 1;

            foreach (ProjectCategoryViewModel item in listVM)
            {
                ProjectCategory projectCategory = await _dataContext.ProjectCategories
                                                  .FirstOrDefaultAsync(x => x.Id == item.Id);

                projectCategory.Position = count;
                count += 1;
            }
            await _dataContext.SaveChangesAsync();
        }
        public IActionResult Create(ProjectCategory category)
        {
            if (ModelState.IsValid)
            {
                _Db.Add(category);
                bool isval = _Db.SaveChanges() > 0;

                if (isval)
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View());
        }
        // GET: ProjectCategories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProjectCategory projectCategory = db.ProjectCategories.Find(id);

            if (projectCategory == null)
            {
                return(HttpNotFound());
            }
            this.AddToastMessage("Warning!", "You are deleting from database and if you delete it can not be undone!", ToastType.Warning);
            return(View(projectCategory));
        }
Пример #17
0
        private static List <ProjectCategory> GetProjectCategories()
        {
            var category1 = new ProjectCategory
            {
                Name = "CircleField"
            };

            var category2 = new ProjectCategory
            {
                Name = "SquareField"
            };

            return(new List <ProjectCategory> {
                category1, category2
            });
        }
Пример #18
0
        public ProjectCategoryCard(ProjectCategory entity)
        {
            Name       = entity.Name;
            CategoryId = entity.Id;

            var cards = new List <ProjectCard>();

            if (entity.Projects != null)
            {
                foreach (var p in entity.Projects)
                {
                    cards.Add(new ProjectCard(p));
                }
            }
            Projects = cards.ToArray();
        }
        // GET: AdminPanel/ProjectCategories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProjectCategory projectCategory = db.ProjectCategories.Find(id);

            if (projectCategory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", projectCategory.CategoryId);
            ViewBag.ProjectId  = new SelectList(db.Projects, "Id", "Name", projectCategory.ProjectId);
            return(View(projectCategory));
        }
Пример #20
0
        public ActionResult Edit(ProjectCategory category)
        {
            if (_db.ProjectCategories.Any(p => (p.Id != category.Id) && (p.Name == category.Name)))
            {
                ModelState.AddModelError("Name", category.Name + " adlı kateqoriyaya deyisiklik edə biməzsiniz");
            }
            if (ModelState.IsValid)
            {
                _db.Entry(category).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }


            return(View(category));
        }
Пример #21
0
    protected void btnSub_Click(object sender, EventArgs e)
    {
        string name            = txtName.Text;
        string project_file    = UpLoadFile();
        string project_content = UeditorHelper.Change(myEditor11.InnerHtml);
        string time            = txtTime.Text;
        string judge_time      = txtJudgeTime.Text;
        string summary         = txtSummary.Text;

        if (name.Length == 0)
        {
            Response.Write("<script>alert('项目类型名称不能为空!');</script>");
        }
        else if (summary.Length == 0)
        {
            Response.Write("<script>alert('内容摘要不能为空!');</script>");
        }
        else if (UpLoadFile() == "")
        {
            Response.Write("<script>alert('请选择正确的文件!');</script>");
        }
        else if (time == "" || judge_time == "")
        {
            Response.Write("<script>alert('截止时间不能为空!');</script>");
        }
        else
        {
            using (var db = new TeachingCenterEntities())
            {
                ProjectCategory pro_category = new ProjectCategory();
                pro_category.name            = name;
                pro_category.category        = getId(dropCategory.SelectedValue);
                pro_category.project_file    = "file/" + project_file;
                pro_category.project_content = project_content;
                pro_category.stage           = 0;
                pro_category.end_time        = time;
                pro_category.judge_end_time  = judge_time;
                pro_category.is_deleted      = 0;
                pro_category.publish_time    = DateTime.Now.ToString("yyyy-MM-dd");
                pro_category.summary         = summary;
                db.ProjectCategory.Add(pro_category);
                db.SaveChanges();
                //Response.Write("<script>alert('提交成功!');location.href='ProCategoryList.aspx';</script>");
                Server.Transfer("ProCategoryList.aspx");
            }
        }
    }
Пример #22
0
        public void SelectedListEntryChanged(object sender, EventArgs e)
        {
            ListBox listBox       = (ListBox)sender;
            String  name          = listBox.Name;
            int     selectedIndex = listBox.SelectedIndex;

            if (name.Equals("listBox_projects"))
            {
                Model.CurrentSelectedProjectIndex = selectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }

                Project selectedProject = new Project(Model.AllProjects[selectedIndex]);
                Model.CurrentProject     = selectedProject;
                Model.LastSelectedObject = selectedProject;
                View.UpdateProjectCategoryList(Model);
            }
            else if (name.Equals("listBox_categories"))
            {
                Model.CurrentSelectedCategoryIndex = selectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }

                ProjectCategory selectedCategory = Model.AllCategories[selectedIndex];
                Model.CurrentSelectedCategory = selectedCategory;
            }
            else if (name.Equals("listBox_editProject_projectCategories"))
            {
                Model.CurrentSelectedProjectCategoryIndex = selectedIndex;
                if (selectedIndex == -1)
                {
                    return;
                }

                Model.CurrentSelectedProjectCategory = Model.CurrentProject.ProjectCategories[selectedIndex];
            }
            else
            {
                Debug.WriteLine("Warning: Could not find action for listbox: " + name);
            }

            View.UpdateEdits(Model);
        }
        public async void handle_ProjectresearcherNull_test()
        {
            Project project = new Project()
            {
                Id = 1
            };
            ProjectCategory   pc = new ProjectCategory();
            ProjectResearcher pr = null;

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Create(It.IsAny <Project>())).Returns(project);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectCategory(It.IsAny <ProjectCategory>())).Returns(pc);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectResearcher(It.IsAny <ProjectResearcher>()))
            .Returns(pr);

            CreateProjectCommand command = new CreateProjectCommand(
                new CreateProjectModel()
            {
                ProjectName = "test",
                Categories  = new List <Category>()
                {
                    new Category()
                    {
                        CategoryId = 1, CategoryName = "test", Created = DateTime.Now, Id = 1
                    }
                },
                ResearcherCategories = new List <ResearcherCategory>()
                {
                    new ResearcherCategory()
                    {
                        Researcher = new Researcher()
                        {
                            Id = 1
                        }, Category = new Category()
                        {
                            Id = 1
                        }
                    }
                }
            });
            CreateProjectHandler handler = new CreateProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.False((bool)result);
        }
Пример #24
0
        public ActionResult Create(ProjectCategory projectCategory)
        {
            if (_db.ProjectCategories.Any(p => p.Name == projectCategory.Name))
            {
                ModelState.AddModelError("Name", projectCategory.Name + " adlı kateqoriya artıq movcuddur");
            }

            if (ModelState.IsValid)
            {
                _db.ProjectCategories.Add(projectCategory);
                _db.SaveChanges();
                return(RedirectToAction(nameof(Index)));
            }


            return(View(projectCategory));
        }
Пример #25
0
        public IActionResult Explore(ProjectCategory category)
        {
            var listprojects = projectService_.SearchProjects(new SearchProjectOptions {
                Category = category
            }).ToList();
            var explore = new ExploreViewModel()
            {
                Category    = category,
                ProjectList = listprojects
            };

            //if (usermodel.P == null)
            //{
            //    return StatusCode((int)user.ErrorCode, user.ErrorText);
            //}

            return(View(explore));
        }
Пример #26
0
        public ActionResult Wood()
        {
            ProjectCategory Wood = new ProjectCategory();

            Wood.Projects = new List <Project>();
            int ElectronicID = db.ProjectTypes.Single(x => x.ProjectTypeDescription == "Wood").ProjectTypeID;

            Wood.ProjectTypeID = ElectronicID;
            List <Project_ProjectType> WoodList = new List <Project_ProjectType>();

            WoodList = db.Project_ProjectTypes.ToList().FindAll(x => x.ProjectTypeID == ElectronicID);
            foreach (Project_ProjectType item in WoodList)
            {
                Wood.Projects.Add(db.Projects.Single(x => x.ProjectID == item.ProjectID));
            }


            return(View(Wood));
        }
Пример #27
0
        public ActionResult Create([Bind(Exclude = "ProjectCategoryID")] ProjectCategory newProjCategory)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                _dataModel.AddToProjectCategories(newProjCategory);
                _dataModel.SaveChanges();

                return(RedirectToAction("Index", "Project"));
            }
            catch
            {
                return(RedirectToAction("Index", "Project"));
            }
        }
Пример #28
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strTitle, strDescription, strMetaTitle, strMetaDescription;
            if (!string.IsNullOrEmpty(Request.QueryString["si"]))
            {
                var oProjectCategory = new ProjectCategory();
                var dv = oProjectCategory.ProjectCategorySelectOne(Request.QueryString["si"]).DefaultView;

                if (dv != null && dv.Count <= 0)
                {
                    return;
                }
                var row = dv[0];
                if (row["CountProject"].ToString() != "0")
                {
                    hdnProjectCategoryID.Value = Request.QueryString["si"];
                }
                else
                {
                    hdnProjectCategoryID.Value = row["ParentID"].ToString();
                }
                strTitle           = Server.HtmlDecode(row["ProjectCategoryName"].ToString());
                strDescription     = Server.HtmlDecode(row["Description"].ToString());
                strMetaTitle       = Server.HtmlDecode(row["MetaTitle"].ToString());
                strMetaDescription = Server.HtmlDecode(row["MetaDescription"].ToString());

                //hdnDesign.Value = progressTitle(dv[0]["ProductCategoryName"].ToString()) + "-dci-" + dv[0]["ProductCategoryID"].ToString() + ".aspx";


                Page.Title = !string.IsNullOrEmpty(strMetaTitle) ? strMetaTitle : strTitle;
                var meta = new HtmlMeta()
                {
                    Name    = "description",
                    Content = !string.IsNullOrEmpty(strMetaDescription) ?
                              strMetaDescription : strDescription
                };
                Header.Controls.Add(meta);
                //lblTitle.Text = strTitle;
            }
        }
    }
Пример #29
0
        public ActionResult EditCategory(ProjectCategory projectCategory)
        {
            if (ModelState.IsValid)
            {
                projectCategoryRepository.Update(projectCategory);

                TempData["Edited"] = "Cateogory Edited.";

                var get_cateogry = eventRepository.Get(projectCategory.Id);

                return(RedirectToAction("ProjectCategoryDetails", new { id = get_cateogry.Id }));
            }
            else
            {
                TempData["EditFailed"] = "Error occurs.";

                return(View(projectCategory));
            }
        }
 public ActionResult AddCategory(ProjectCategory pc)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Repository.CreateProjectCategory(pc);
         }
         else
         {
             return(PartialView("ProjectCategoryPartialViews/_AddCategory", pc));
         }
         return(PartialView("ProjectCategoryPartialViews/_CategorySuccess"));
     }
     catch
     {
         return(View("_Error"));
     }
 }
Пример #31
0
        private static void InsertProjectCategory_Project()
        {
            try
            {
                var status = GetStatus();
                var projectCategory = new ProjectCategory
                {
                    Name = "Internal",

                };
                var project = new Project
                {
                    Name = "Jira1",
                    CompanyId = 1,
                    //ProjectId = Guid.NewGuid(),
                    //Works = {new Work(Guid.NewGuid()) {StatusId=status[0].StatusId,  TimeRange_Start=DateTime.Now.AddDays(-5),TimeRange_End=DateTime.Now.AddDays(-4) },
                    //    new Work(Guid.NewGuid()) {StatusId=status[0].StatusId, TimeRange_Start=DateTime.Now.AddDays(-3),TimeRange_End=DateTime.Now.AddDays(-2) }}
                };
                //project.ProjectCategory = projectCategory;
                projectCategory.Projects.Add(project);
                using (var context = new CrudContext())
                {
                    context.ProjectCategories.Add(projectCategory);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e);
            }
        }
Пример #32
0
        private static void InsertProjectCategoryAndSave()
        {
            var projectCategory = new ProjectCategory { Name = "Test" };
            _repository.InsertProjectCategoryAndSave(ref projectCategory);

            GetProjectCategory(projectCategory.Id);
        }
Пример #33
0
 private static void InsertProjectCategory()
 {
     var projectCategory = new ProjectCategory { Name = "Internal" };
     using (var context = new CrudContext())
     {
         context.ProjectCategories.Add(projectCategory);
         context.SaveChanges();
     }
     GetProjectCategory(projectCategory.Id);
 }
Пример #34
0
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "QuickUpdate")
        {
            string ProjectCategoryID, IsShowOnMenu, IsShowOnHomePage, IsAvailable;
            var oProjectCategory = new ProjectCategory();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                ProjectCategoryID = item.GetDataKeyValue("ProjectCategoryID").ToString();
                IsShowOnMenu = ((CheckBox)item.FindControl("chkIsShowOnMenu")).Checked.ToString();
                IsShowOnHomePage = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oProjectCategory.ProjectCategoryQuickUpdate(
                    ProjectCategoryID,
                    IsShowOnMenu,
                    IsShowOnHomePage,
                    IsAvailable
                );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oProjectCategory = new ProjectCategory();
            var errorList = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                var isChildCategoryExist = oProjectCategory.ProjectCategoryIsChildrenExist(item.GetDataKeyValue("ProjectCategoryID").ToString());
                var ProjectCategoryName = ((Label)item.FindControl("lblProjectCategoryName")).Text;
                var ProjectCategoryNameEn = ((Label)item.FindControl("lblProjectCategoryNameEn")).Text;
                if (isChildCategoryExist)
                {
                    errorList += ", " + ProjectCategoryName;
                }
                else
                {
                    string strImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;

                    if (!string.IsNullOrEmpty(strImageName))
                    {
                        string strSavePath = Server.MapPath("~/res/projectcategory/" + strImageName);
                        if (File.Exists(strSavePath))
                            File.Delete(strSavePath);
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Danh mục <b>\"" + errorList.Remove(0, 1).Trim() + "\"</b> đang có danh mục con hoặc sản phẩm.<br /> Xin xóa danh mục con hoặc sản phẩm trong danh mục này hoặc thiết lập hiển thị = \"không\".";
                lblError.Text = strAlertMessage;
            }
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command = e.CommandName;
            var row = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileImageName = (RadUpload)row.FindControl("FileImageName");

            string strProjectCategoryName = ((RadTextBox)row.FindControl("txtProjectCategoryName")).Text.Trim();
            string strProjectCategoryNameEn = ((RadTextBox)row.FindControl("txtProjectCategoryNameEn")).Text.Trim();
            string strConvertedProjectCategoryName = Common.ConvertTitle(strProjectCategoryName);
            string strDescription = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string strDescriptionEn = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescriptionEn")).Content.Trim()));
            string strContent = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string strContentEn = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContentEn")).Content.Trim()));
            string strMetaTitle = ((RadTextBox)row.FindControl("txtMetaTitle")).Text.Trim();
            string strMetaTitleEn = ((RadTextBox)row.FindControl("txtMetaTitleEn")).Text.Trim();
            string strMetaDescription = ((RadTextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string strMetaDescriptionEn = ((RadTextBox)row.FindControl("txtMetaDescriptionEn")).Text.Trim();
            string strImageName = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            string strParentID = ((RadComboBox)row.FindControl("ddlParent")).SelectedValue;
            string strIsAvailable = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strIsShowOnMenu = ((CheckBox)row.FindControl("chkIsShowOnMenu")).Checked.ToString();
            string strIsShowOnHomePage = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();


            var oProjectCategory = new ProjectCategory();

            if (e.CommandName == "PerformInsert")
            {
                strImageName = oProjectCategory.ProjectCategoryInsert(
                    strProjectCategoryName,
                    strProjectCategoryNameEn,
                    strConvertedProjectCategoryName,
                    strDescription,
                    strDescriptionEn,
                    strContent,
                    strContentEn,
                    strMetaTitle,
                    strMetaTitleEn,
                    strMetaDescription,
                    strMetaDescriptionEn,
                    strImageName,
                    strParentID,
                    strIsShowOnMenu,
                    strIsShowOnHomePage,
                    strIsAvailable
                );

                string strFullPath = "~/res/projectcategory/" + strImageName;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 40, 40);
                }
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam = ObjectDataSource1.UpdateParameters;
                var strProjectCategoryID = row.GetDataKeyValue("ProjectCategoryID").ToString();
                var strOldImageName = ((HiddenField)row.FindControl("hdnImageName")).Value;
                var strOldImagePath = Server.MapPath("~/res/projectcategory/" + strOldImageName);

                dsUpdateParam["ProjectCategoryName"].DefaultValue = strProjectCategoryName;
                dsUpdateParam["ProjectCategoryNameEn"].DefaultValue = strProjectCategoryNameEn;
                dsUpdateParam["ConvertedProjectCategoryName"].DefaultValue = strConvertedProjectCategoryName;
                dsUpdateParam["Description"].DefaultValue = strDescription;
                dsUpdateParam["DescriptionEn"].DefaultValue = strDescriptionEn;
                dsUpdateParam["Content"].DefaultValue = strContent;
                dsUpdateParam["ContentEn"].DefaultValue = strContentEn;
                dsUpdateParam["ImageName"].DefaultValue = strImageName;
                dsUpdateParam["ParentID"].DefaultValue = strParentID;
                dsUpdateParam["IsShowOnMenu"].DefaultValue = strIsShowOnMenu;
                dsUpdateParam["IsShowOnHomePage"].DefaultValue = strIsShowOnHomePage;
                dsUpdateParam["IsAvailable"].DefaultValue = strIsAvailable;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    var strFullPath = "~/res/projectcategory/" + strConvertedProjectCategoryName + "-" + strProjectCategoryID + strImageName.Substring(strImageName.LastIndexOf('.'));

                    if (File.Exists(strOldImagePath))
                        File.Delete(strOldImagePath);

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 40, 40);
                }
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oProjectCategory = new ProjectCategory();
            var lnkDeleteImage = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strProjectCategoryID = s[0];
            var strImageName = s[1];

            oProjectCategory.ProjectCategoryImageDelete(strProjectCategoryID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }
Пример #35
0
 protected void lnkDownOrder_Click(object sender, EventArgs e)
 {
     var lnkDownOrder = (LinkButton)sender;
     var strProjectCategoryID = lnkDownOrder.Attributes["rel"];
     var oProjectCategory = new ProjectCategory();
     oProjectCategory.ProjectCategoryDownOrder(strProjectCategoryID);
     RadGrid1.Rebind();
 }
Пример #36
0
    /**
     * Register an existing project with the provided category IDs
     *
     * Project must be persisted in the database at this point. If the project is already registered with
     * a provided category, this method will skip that category.
     *
     */
    public void registerProjectCategories(Project project, IList<Int64> categoryIds)
    {
        if (session == null || !session.IsOpen)
        {
            session = hibernate.getSession();
        }

        if(project.PROJECT_ID == null || project.PROJECT_ID == 0)
            throw new ProjectCategoryRegistrationException("Project "+project.PROJECT_TITLE+" is not submitted yet. Please submit project first.");

        Project existingProject = session.CreateCriteria<Project>()
                            .Add(Restrictions.Eq("PROJECT_ID", project.PROJECT_ID))
                            .UniqueResult<Project>();
        if(existingProject == null)
            throw new ProjectCategoryRegistrationException("Project " + project.PROJECT_TITLE + " is not submitted yet. Please submit project first.");

        //Validate all selected categories exist
        IList<Category> existingCategories = session.CreateCriteria<Category>()
                                                .Add(Restrictions.In("CATEGORY_ID", categoryIds.ToArray()))
                                                .List<Category>();

        if (existingCategories.Count != categoryIds.Count) //we can only do this if categoryId is unique
            throw new ProjectCategoryRegistrationException("Some categories do not exist and must be created first.");

        //start creating ProjectCategory objects to link the 2 up
        //impt! use those objects retrieved from the database in the above steps
        session.BeginTransaction();
        foreach (Category category in existingCategories)
        {
            ProjectCategory projectCategory = new ProjectCategory();
            projectCategory.CATEGORY = category;
            projectCategory.PROJECT = existingProject;
            existingProject.CATEGORIES.Add(projectCategory);
            category.CATEGORIES.Add(projectCategory);

            session.Save(projectCategory);

        }
        session.Save(existingProject);

        session.Transaction.Commit();
    }