Exemplo n.º 1
0
        public ActionResult Edit(string paidText, string unpaidText)
        {
            // get the default template
            var template = Repository.OfType<Template>().Queryable.Where(a => a.Default).FirstOrDefault();

            // check to see if it's null, just send a blank one
            if (template == null) template = new Template();

            // update the text
            template.Text = paidText + StaticValues.ConfirmationTemplateDelimiter + unpaidText;
            if(template.Text.Trim() == StaticValues.ConfirmationTemplateDelimiter)
            {
                ModelState.AddModelError("Text", "text may not be null or empty");
            } else if (string.IsNullOrWhiteSpace(paidText))
            {
                ModelState.AddModelError("Text", "text may not be null or empty");
            }

            // ensure the default value
            template.Default = true;

            // validate
            template.TransferValidationMessagesTo(ModelState);
            var viewModel = ConfirmationTemplateViewModel.Create(template);
            if (ModelState.IsValid)
            {
                Repository.OfType<Template>().EnsurePersistent(template);
                Message = NotificationMessages.STR_ObjectSaved.Replace(NotificationMessages.ObjectType, "Template");

                return View(viewModel);
            }

            Message = NotificationMessages.STR_UnableToUpdate.Replace(NotificationMessages.ObjectType, "Template");
            return View(viewModel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// GET: /Template/Edit
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit()
        {
            // get the default template
            var template = Repository.OfType<Template>().Queryable.Where(a => a.Default).FirstOrDefault();

            // check to see if it's null, just send a blank one
            if (template == null) template = new Template();
            var viewModel = ConfirmationTemplateViewModel.Create(template);

            return View(viewModel);
        }
Exemplo n.º 3
0
        public static ConfirmationTemplateViewModel Create(Template template)
        {
            Check.Require(template != null, "Template is required.");

            var viewModel = new ConfirmationTemplateViewModel{Template = template};
            if (template.Text != null && template.Text.Contains(StaticValues.ConfirmationTemplateDelimiter))
            {
                //var index = template.Text.IndexOf("<<PaidTextAbove>>");
                var delimiter = new string[] { StaticValues.ConfirmationTemplateDelimiter };
                var parse = template.Text.Split(delimiter, StringSplitOptions.None);
                viewModel.PaidText = parse[0];
                viewModel.UnpaidText = parse[1];
            }
            else
            {
                viewModel.PaidText = template.Text ?? string.Empty;
                viewModel.UnpaidText = string.Empty;
            }
            return viewModel;
        }
Exemplo n.º 4
0
        public JsonNetResult SaveTemplate(int id, string textPaid, string textUnpaid)
        {
            var item = Repository.OfType<Item>().GetNullableById(id);

            if (item == null || string.IsNullOrEmpty(textPaid) || !Access.HasItemAccess(CurrentUser, item))
            {
                return new JsonNetResult(null);
            }

            var template = new Template(textPaid + StaticValues.ConfirmationTemplateDelimiter + textUnpaid);
            template.Default = false;
            template.Item = item;
            item.Template = template;

            if (template.Text.Trim() == StaticValues.ConfirmationTemplateDelimiter)
            {
                ModelState.AddModelError("Text", "text may not be null or empty");
            }

            MvcValidationAdapter.TransferValidationMessagesTo(ModelState, item.ValidationResults());
            MvcValidationAdapter.TransferValidationMessagesTo(ModelState, template.ValidationResults());

            if (ModelState.IsValid)
            {
                Repository.OfType<Item>().EnsurePersistent(item);
                return new JsonNetResult(true);
            }

            return new JsonNetResult(null);
        }
Exemplo n.º 5
0
        public ActionResult Create(Item item, ExtendedPropertyParameter[] extendedProperties, string[] tags, string mapLink)
        {
            ModelState.Clear();
            // get the file and add it into the item
            if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
            {
                var file = Request.Files[0];
                var reader = new BinaryReader(file.InputStream);
                item.Image = reader.ReadBytes(file.ContentLength);
            }
            if (item.Image == null || item.Image.Length <= 0)
            {
                ModelState.AddModelError("Image", @"An image is required.");
            }
            // process the extended properties and tags
            //item = PopulateObject.Item(Repository, item, extendedProperties, tags);
            item = Copiers.PopulateItem(Repository, item, extendedProperties, tags, mapLink);

            if(item.ExtendedPropertyAnswers != null && item.ExtendedPropertyAnswers.Count > 0)
            {
                foreach (var extendedPropertyAnswer in item.ExtendedPropertyAnswers)
                {
                    if(string.IsNullOrWhiteSpace(extendedPropertyAnswer.Answer))
                    {
                        ModelState.AddModelError("Extended Properties", "All Extended Properties are required");
                        break;
                    }
                }
            }

            var user = Repository.OfType<User>().Queryable.Where(a => a.LoginID == CurrentUser.Identity.Name).FirstOrDefault();

            // add permissions
            var editor = new Editor(item, user);
            editor.Owner = true;
            item.AddEditor(editor);

            // set the unit
            //item.Unit = user.Units.FirstOrDefault();

            // add the required question set
            var questionSet =
                Repository.OfType<QuestionSet>().Queryable.Where(
                    a => a.Name == StaticValues.QuestionSet_ContactInformation).FirstOrDefault();

            // this should really not be null at any point.
            if (questionSet != null)
            {
                item.AddTransactionQuestionSet(questionSet);
            }

            if (item.ItemType != null)
            {
                // add the default question sets
                foreach (var qs in item.ItemType.QuestionSets)
                {
                    if (qs.TransactionLevel)
                    {
                        item.AddTransactionQuestionSet(qs.QuestionSet);
                    }
                    else
                    {
                        item.AddQuantityQuestionSet(qs.QuestionSet);
                    }
                }
            }

            if(item.Template == null)
            {
                var tempTemplate = Repository.OfType<Template>().Queryable.Where(a => a.Default).FirstOrDefault();
                if (tempTemplate != null && !string.IsNullOrEmpty(tempTemplate.Text))
                {
                    var template = new Template(tempTemplate.Text);
                    item.Template = template;
                }
            }

            MvcValidationAdapter.TransferValidationMessagesTo(ModelState, item.ValidationResults());

            if (ModelState.IsValid)
            {
                Repository.OfType<Item>().EnsurePersistent(item);
                Message = NotificationMessages.STR_ObjectCreated.Replace(NotificationMessages.ObjectType, "Item");
                return this.RedirectToAction(a => a.List(null));
            }
            else
            {
                var viewModel = ItemViewModel.Create(Repository, CurrentUser, item);
                viewModel.IsNew = true;
                return View(viewModel);
            }
        }