Пример #1
0
        public JsonResult GetMinistry(int id)
        {
            try
            {
                Organization organization = Organization.Find(SessionContext, id);

                MinistryViewModel ministry = new MinistryViewModel
                {
                    ID   = organization.ID,
                    Code = organization.Code,
                    Name = organization.CurrentName.Name.GetValue(SessionContext.CurrentLanguage.Code)
                };

                if (organization == null)
                {
                    SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Get, MessageException.Null("The static method Find return null, ID : " + id));
                    return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { Success = true, ministry }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Get, MessageException.Fail(ex.Message));
                return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public ActionResult Create(MinistryViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                // Create a new ministry object
                Ministry myMinistry = new Ministry(viewModel);

                // Create or update a new address record
                Address myAddress = _db.Addresses.Add(viewModel.Address);

                // Update the AddressFK in the ministry object
                myMinistry.AddressId = myAddress.id;

                // Add the ministry to the dataset
                this._db.Ministries.Add(myMinistry);

                // Update the database
                this._db.SaveChanges();

                // We are done, lets get outahere
                Response.Redirect("~/Ministry");
            }
            else
            {
                var errors = ModelState.Where(v => v.Value.Errors.Any());
            }

            return(View(viewModel));
        }
Пример #3
0
 public Ministry(MinistryViewModel viewModel)
 {
     id           = viewModel.MinistryId;
     MinistryName = viewModel.Name;
     AddressId    = viewModel.AddressId;
     LeadMentorId = viewModel.LeadMentorId;
     Description  = viewModel.Description;
     MainPhoneId  = viewModel.PhoneId;
 }
Пример #4
0
        public async Task <IActionResult> EditMinistry(MinistryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = model.ImageUrl;
                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile);
                }
                var ministry = await _converterHelper.ToMinistryAsync(model, path, true);

                _context.Ministries.Update(ministry);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"Details/{model.AdminId}"));
            }
            return(View(model));
        }
Пример #5
0
        public async Task <Ministry> ToMinistryAsync(MinistryViewModel model, string path, bool isNew)
        {
            var ministry = new Ministry
            {
                //  ChurchEvents = model.ChurchEvents,
                FollowUpHistories = model.FollowUpHistories,
                Id           = isNew ? 0 : model.Id,
                ImageUrl     = path,
                Name         = model.Name,
                Admin        = await _Context.Admins.FindAsync(model.AdminId),
                MinistryType = await _Context.MinistryTypes.FindAsync(model.MinistryTypeId)
            };

            if (model.Id != 0)
            {
                ministry.Id = model.Id;
            }
            return(ministry);
        }
Пример #6
0
        }      // GET: Admins/AddMinistry/5

        public async Task <IActionResult> AddMinistry(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var admin = await _context.Admins.FindAsync(id.Value);

            if (admin == null)
            {
                return(NotFound());
            }
            var model = new MinistryViewModel
            {
                AdminId       = admin.Id,
                MinistryTypes = _combosHelper.GetComboMinistryTypes()
            };

            return(View(model));
        }
Пример #7
0
        public ActionResult Edit(MinistryViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Ministry myMinistry = this._db.Ministries.Find(viewModel.MinistryId);
                if (myMinistry != null)
                {
                    myMinistry.MinistryName = viewModel.Name;
                    myMinistry.MainPhoneId  = viewModel.PhoneId;
                    myMinistry.LeadMentorId = viewModel.LeadMentorId;
                    myMinistry.Description  = viewModel.Description;
                    myMinistry.AddressId    = viewModel.AddressId;

                    _db.SaveChanges();

                    Response.Redirect("~/Staff");
                }
            }

            return(View(viewModel));
        }
Пример #8
0
        public async Task LoadMinisterData(MinistryViewModel model, Ministry ministry)
        {
            using (Profiler.StepStatic("Loading Minister Data"))
            {
                model.Ministry = ministry;

                model.Minister = await Repository.GetMinisterAsync(ministry.Key);

                if (ministry.ChildMinistryKey != null)
                {
                    model.ChildMinistry = (await Repository.GetMinistryAsync(ministry.ChildMinistryKey)).Index as Ministry;
                }

                if (model.ChildMinistry != null && "Speeches".Equals(model.ChildMinistry.Key, StringComparison.CurrentCultureIgnoreCase))
                {
                    model.ChildMinistry = null;
                }

                if (model.ChildMinistry != null)
                {
                    model.ChildMinistryMinister = await Repository.GetMinisterAsync(model.ChildMinistry.Key);
                }
            }
        }
        private MinistryEditViewModel CompileEditMinistryModel(MinistryViewModel modelWithData)
        {
            var ministryOwners       = _ministryHelper.GetMinistryOwners();
            var practices            = _ministryHelper.GetPractices();
            var funnels              = _ministryHelper.GetFunnels();
            var campuses             = _ministryHelper.GetCampuses();
            var locations            = _ministryHelper.GetLocations();
            var levelOfImportances   = _ministryHelper.GetLevelOfImportances();
            var approvals            = _ministryHelper.GetApprovals();
            var frequencies          = _ministryHelper.GetFrequencies();
            var upInOuts             = _ministryHelper.GetUpInOutOptions();
            var resourceInvolvements = _ministryHelper.GetResourceInvolvementOptions();


            var ministryOwnerDropDown = ministryOwners.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var practiceDropDown = practices.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var funnelDropDown = funnels.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var campusDropDown = campuses.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var locationDropDown = locations.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var levelOfImportanceDropDown = levelOfImportances.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var approvalDropDown = approvals.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var frequencyDropDown = frequencies.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var upInOutListBox = upInOuts.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });

            var resourceInvolvementListBox = resourceInvolvements.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.Name
            });


            var viewModel = new MinistryEditViewModel
            {
                MinistryOwners       = ministryOwnerDropDown,
                Practices            = practiceDropDown,
                Funnels              = funnelDropDown,
                Campuses             = campusDropDown,
                Locations            = locationDropDown,
                Approvals            = approvalDropDown,
                Frequencies          = frequencyDropDown,
                LevelOfImportances   = levelOfImportanceDropDown,
                UpInOuts             = upInOutListBox,
                ResourceInvolvements = resourceInvolvementListBox,
                Id                             = modelWithData.Id,
                Event                          = modelWithData.Event,
                Purpose                        = modelWithData.Purpose,
                DesiredOutcome                 = modelWithData.DesiredOutcome,
                MinistryOwnerId                = modelWithData.MinistryOwnerId,
                PracticeId                     = modelWithData.PracticeId,
                FunnelId                       = modelWithData.FunnelId,
                LocationId                     = modelWithData.LocationId,
                CampusId                       = modelWithData.CampusId,
                StartDate                      = modelWithData.StartDate,
                EndDate                        = modelWithData.EndDate,
                FrequencyId                    = modelWithData.FrequencyId,
                KidCare                        = modelWithData.KidCare,
                LevelOfImportanceId            = modelWithData.LevelOfImportanceId,
                ApprovalId                     = modelWithData.ApprovalId,
                Comments                       = modelWithData.Comments,
                UpInOutIds                     = modelWithData.UpInOutRelationships.Select(x => x.UpInOutId).ToArray(),
                SelectedResourceInvolvementIds = modelWithData.ResourceInvolvementRelationships.Select(x => x.ResourceInvolvementId).ToArray(),
                Archived                       = modelWithData.Archived
            };

            return(viewModel);
        }