Example #1
0
        protected void btnOK_OnClick(object sender, EventArgs e)
        {
            var model = projectControl.Model;

            if (String.IsNullOrWhiteSpace(model.Name))
            {
                lblErrorMessage.Text = "შეიყვანეთ სახელი";

                mpeProject.Show();
                return;
            }

            var converter = new ProjectModelEntityConverter(HbSession);

            var project = HbSession.Query <UM_Project>().FirstOrDefault(n => n.ID == model.ID);

            if (project == null)
            {
                project = new UM_Project
                {
                    ID          = Guid.NewGuid(),
                    DateCreated = DateTime.Now
                };
            }

            converter.FillObject(project, model);

            HbSession.SubmitChanges(project);

            FillProjectsGrid();

            mpeProject.Hide();
        }
Example #2
0
        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            var converter = new ProjectModelEntityConverter(DataContext);

            var model = (ProjectModel)null;

            if (mainProjectControl.Visible)
            {
                model = mainProjectControl.Model;
            }
            else
            {
                model = subProjectControl.Model;
            }

            if (model.ID != null)
            {
                var entity = DataContext.LP_Projects.FirstOrDefault(n => n.ID == model.ID);
                if (entity == null)
                {
                    return;
                }

                converter.FillObject(entity, model);
            }
            else
            {
                var entity = converter.Convert(model);

                var query = (from n in DataContext.LP_Projects
                             where n.DateDeleted == null
                             select n);

                if (model.ParentID == null)
                {
                    query = (from n in query
                             where n.ParentID == null
                             select n);
                }
                else
                {
                    query = (from n in query
                             where n.ParentID == model.ParentID
                             select n);
                }

                var maxOrder = query.Max(n => n.OrderIndex);
                entity.OrderIndex = maxOrder.GetValueOrDefault() + 1;

                DataContext.LP_Projects.InsertOnSubmit(entity);
            }

            DataContext.SubmitChanges();

            mpeAddEdit.Hide();

            FillDataGrid();
        }