Exemplo n.º 1
0
        public static bool Add(this MinistryModel model, out Status status)
        {
            try
            {
                using (var db = new DbContextHelper())
                {
                    var entity = db.Ministries.Create();
                    entity.IdKey       = Guid.NewGuid();
                    entity.Name        = model.Name;
                    entity.Description = model.Description.Sanitize();
                    entity.Created     = DateTime.Now;

                    entity = db.Ministries.Add(entity);
                    db.SaveChanges();

                    model.Id    = entity.Id;
                    model.IdKey = entity.IdKey;

                    status = Status.Success;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogFatalError("Manage.MinistryModelHelper.Add", ex);
                status = Status.SystemException;
            }

            return(false);
        }
Exemplo n.º 2
0
        public static bool Update(this MinistryModel model, out Status status)
        {
            try
            {
                using (var db = new DbContextHelper())
                {
                    var entity = (from m in db.Ministries
                                  where m.IdKey == model.IdKey
                                  select m).FirstOrDefault();

                    if (entity == null)
                    {
                        status = Status.DataNotFound;
                        return(false);
                    }

                    entity.Name        = model.Name;
                    entity.Description = model.Description.Sanitize();
                    entity.Modified    = DateTime.Now;

                    db.SaveChanges();

                    status = Status.Success;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogFatalError("ManageMinistryModelHelper.Update", ex);
                status = Status.SystemException;
            }

            return(false);
        }
Exemplo n.º 3
0
        public static MinistryModel GetMinistryModel(this Ministry ministry)
        {
            var model = new MinistryModel
            {
                Id          = ministry.Id,
                IdKey       = ministry.IdKey,
                Name        = ministry.Name,
                Description = ministry.Description
            };

            return(model);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a entity model used by the MinistriesController.Add method
        /// </summary>
        /// <returns></returns>
        public static MinistryModel GetMinistryModelForAdd()
        {
            var  model     = new MinistryModel();
            Guid userIdKey = ManageUserModelHelper.GetFormsAuthenticationTicket().IdKey();

            model.PageTitle = "Holy Angels System Ministry";
            model.SubTitle  = "Add New Ministry";
            model.UserIdKey = userIdKey;

            model.MetaDescription = "";
            model.MetaKeywords    = "";
            model.MetaSubject     = "";

            return(model);
        }
Exemplo n.º 5
0
        public virtual ActionResult Edit(MinistryModel model)
        {
            if (ModelState.IsValid)
            {
                Status status;
                if (model.Update(out status))
                {
                    ModelState.AddModelError("Error", "Successfully updated ministry");
                }
                else
                {
                    ModelState.AddModelError("Error", status.Message());
                }
            }
            else
            {
                ModelState.AddModelError("Error", "Please update the required fields");
            }

            return(View(model));
        }
Exemplo n.º 6
0
        //[HttpPost]
        public virtual ActionResult DisplayMinistry(string ministryName)
        {
            var model = new MinistryModel();

            return(View(model));
        }