Esempio n. 1
0
        /// <summary>
        /// Handles the Click event of the btnSaveMatrixItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnSaveMatrixItem_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();
            var attributeMatrixItemService          = new AttributeMatrixItemService(rockContext);
            AttributeMatrixItem attributeMatrixItem = null;
            int attributeMatrixItemId = _hfMatrixItemId.Value.AsInteger();

            if (attributeMatrixItemId > 0)
            {
                attributeMatrixItem = attributeMatrixItemService.Get(attributeMatrixItemId);
            }

            if (attributeMatrixItem == null)
            {
                attributeMatrixItem = new AttributeMatrixItem();
                attributeMatrixItem.AttributeMatrix = new AttributeMatrixService(rockContext).Get(this.AttributeMatrixGuid.Value);
                attributeMatrixItemService.Add(attributeMatrixItem);
            }

            attributeMatrixItem.LoadAttributes(rockContext);
            Rock.Attribute.Helper.GetEditValues(_phMatrixItemAttributes, attributeMatrixItem);
            rockContext.SaveChanges();
            attributeMatrixItem.SaveAttributeValues(rockContext);

            _gMatrixItems.Visible      = true;
            _pnlEditMatrixItem.Visible = false;

            BindGrid(this.AttributeMatrixGuid);
        }
        protected void Distribute_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            RockContext    rockContext    = new RockContext();
            HistoryService historyService = new HistoryService(rockContext);
            var            keys           = (( string )e.RowKeyValue).SplitDelimitedValues();
            var            personId       = keys[0].AsInteger();
            var            matrixId       = keys[1].AsInteger();
            var            scheduleGuid   = keys[2].AsGuid();

            AttributeMatrixItemService attributeMatrixItemService = new AttributeMatrixItemService(rockContext);
            var matrix = attributeMatrixItemService.Get(matrixId);

            matrix.LoadAttributes();
            var category = new CategoryService(rockContext).Get(GetAttributeValue("HistoryCategory").AsGuid());

            History history = new History()
            {
                CategoryId          = category.Id,
                EntityTypeId        = EntityTypeCache.GetId <Person>().Value,
                EntityId            = personId,
                RelatedEntityTypeId = EntityTypeCache.GetId <AttributeMatrixItem>().Value,
                RelatedEntityId     = matrixId,
                Verb        = "Distributed",
                Caption     = "Medication Distributed",
                Summary     = string.Format("<span class=\"field-name\">{0}</span> was distributed at <span class=\"field-name\">{1}</span>", matrix.GetAttributeValue("Medication"), Rock.RockDateTime.Now),
                RelatedData = scheduleGuid.ToString()
            };

            historyService.Add(history);
            rockContext.SaveChanges();
            BindGrid();
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the Click event of the deleteField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        private void gMatrixItems_DeleteClick(object sender, RowEventArgs e)
        {
            int attributeMatrixItemId = e.RowKeyId;
            var rockContext           = new RockContext();
            AttributeMatrixItemService attributeMatrixItemService = new AttributeMatrixItemService(rockContext);
            AttributeMatrixItem        attributeMatrixItem        = attributeMatrixItemService.Get(attributeMatrixItemId);

            if (attributeMatrixItem != null)
            {
                var attributeMatrix = attributeMatrixItem.AttributeMatrix;
                attributeMatrixItemService.Delete(attributeMatrixItem);
                rockContext.SaveChanges();

                BindGrid(this.AttributeMatrixGuid);
            }
        }
        protected void mdEdit_SaveClick(object sender, EventArgs e)
        {
            RockContext rockContext  = new RockContext();
            NoteService noteService  = new NoteService(rockContext);
            var         keys         = (ddlMatrixItem.SelectedValue).SplitDelimitedValues();
            var         personId     = keys[0].AsInteger();
            var         matrixId     = keys[1].AsInteger();
            var         scheduleGuid = keys[2].AsGuid();

            AttributeMatrixItemService attributeMatrixItemService = new AttributeMatrixItemService(rockContext);
            var matrix = attributeMatrixItemService.Get(matrixId);

            matrix.LoadAttributes();
            var noteType = NoteTypeCache.Get(GetAttributeValue("NoteType").AsGuid());


            var noteId = hfNoteId.ValueAsInt();
            var note   = noteService.Get(noteId);

            if (note == null)
            {
                note = new Note
                {
                    NoteTypeId  = noteType.Id,
                    EntityId    = personId,
                    ForeignId   = matrixId,
                    ForeignGuid = scheduleGuid,
                    Caption     = "Medication Distributed"
                };
                noteService.Add(note);
            }

            note.Text = string.Format(
                "<span class=\"field-name\">{0}</span> was distributed at <span class=\"field-name\">{1}</span>",
                matrix.GetAttributeValue("Medication"),
                dtpDateTime.SelectedDateTime.Value);

            note.CreatedDateTime = dtpDateTime.SelectedDateTime.Value;

            rockContext.SaveChanges(true);

            mdEdit.Hide();
            ShowNotesModal(hfPersonId.ValueAsInt());
        }
        protected void Distribute_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            RockContext rockContext  = new RockContext();
            NoteService noteService  = new NoteService(rockContext);
            var         keys         = (( string )e.RowKeyValue).SplitDelimitedValues();
            var         personId     = keys[0].AsInteger();
            var         matrixId     = keys[1].AsInteger();
            var         scheduleGuid = keys[2].AsGuid();

            AttributeMatrixItemService attributeMatrixItemService = new AttributeMatrixItemService(rockContext);
            var matrix = attributeMatrixItemService.Get(matrixId);

            matrix.LoadAttributes();
            var noteType = NoteTypeCache.Get(GetAttributeValue("NoteType").AsGuid());

            Note history = new Note()
            {
                NoteTypeId  = noteType.Id,
                EntityId    = personId,
                ForeignId   = matrixId,
                Caption     = "Medication Distributed",
                Text        = string.Format("<span class=\"field-name\">{0}</span> was distributed at <span class=\"field-name\">{1}</span>", matrix.GetAttributeValue("Medication"), Rock.RockDateTime.Now),
                ForeignGuid = scheduleGuid
            };

            noteService.Add(history);
            rockContext.SaveChanges();

            //for clicking distribute after the fact
            if (dpDate.SelectedDate.HasValue && dpDate.SelectedDate.Value.Date != Rock.RockDateTime.Today)
            {
                history.CreatedDateTime = dpDate.SelectedDate.Value;
                rockContext.SaveChanges();
            }

            BindGrid();
        }