コード例 #1
0
        public void Edit_Test_ValidInput()
        {
            // Arrange
            ReviewViewModel oldReview = CreateReviewFromForm(collection);

            rLogic.PostReview(oldReview);
            oldReview = rLogic.GetReviews().FirstOrDefault();
            FormCollection newCollection = new FormCollection
            {
                { "BreweryID", brewery.BreweryID.ToString() },
                { "UserID", user.UserID.ToString() }
            };

            foreach (var i in collection.AllKeys)
            {
                newCollection.Add(i, collection.GetValue(i).AttemptedValue);
            }
            newCollection.Set("ReviewDescription", "new description");

            // Act
            RedirectToRouteResult result = controller.Edit(oldReview.ReviewID, newCollection) as RedirectToRouteResult;

            // Assert
            ReviewViewModel newReview = rLogic.GetReviews().FirstOrDefault();

            Assert.AreNotEqual(newReview.ReviewDescription, collection["ReviewDescription"]);
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: athel4/hui_von
        public ActionResult PlaceOrder(FormCollection _form)
        {
            JObject oJson = new JObject(
                new JProperty("status", 0),
                new JProperty("message", string.Empty));

            APITest.apiCommon.Order oData = new APITest.apiCommon.Order();
            Models.ViewModel        oVM   = new Models.ViewModel();
            oVM.oApiFixRate.Call();
            oVM.oApiProduct.Call();
            var oItem = oVM.oApiProduct.Value.Where(x => x.productId == _form.Get("reqid")).FirstOrDefault();

            if (oItem.maximumQuantity != null)
            {
                if (oItem.maximumQuantity < Convert.ToInt32(_form.Get("reqqty")))
                {
                    _form.Set("reqqty", oItem.maximumQuantity.ToString());
                }

                APITest.apiCommon.Lineitems        oLineItems = new APITest.apiCommon.Lineitems();
                List <APITest.apiCommon.Lineitems> oList      = new List <APITest.apiCommon.Lineitems>();
                oLineItems.productId = _form.Get("reqid").ToString();
                oLineItems.quantity  = Convert.ToInt32(_form.Get("reqqty"));
                APITest.apiCommon.Order oOrder = new APITest.apiCommon.Order();
                oList.Add(oLineItems);
                oOrder.customerName  = Request.Cookies["username"].ToString();
                oOrder.customerEmail = Request.Cookies["email"].ToString();
                oOrder.lineItems     = oList;

                oVM.oApiOrder.Call(JsonConvert.SerializeObject(oOrder, Formatting.Indented));
                if (!string.IsNullOrEmpty(oVM.oApiOrder.Value))
                {
                    oJson["message"] = oVM.oApiOrder.Value;
                }
                else
                {
                    oJson["message"] = "No Result";
                }
            }
            else if (oItem.maximumQuantity != null && Convert.ToInt32(_form.Get("reqqty")) > 0)
            {
                oJson["message"] = "Unable To Get The Remaining Quantity From Supplier";
            }
            return(Content(JsonConvert.SerializeObject(oJson, Formatting.Indented)));
        }
コード例 #3
0
        public void FillIn_ErrorWithRequiredField()
        {
            FormViewModel formViewModel = new FormViewModel();

            formViewModel.Title = "Required Form Name";
            Template template = _formManager.CreateNewFormAndTemplate(formViewModel);

            Assert.IsNotNull(template);

            TemplateViewModel templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID);

            FormCollection fieldCollection = new FormCollection();
            IDictionary <string, string> fields;

            CeateFieldForm(1, Constants.TemplateFieldType.TEXTBOX.ToString(), fieldCollection, out fields);

            fieldCollection.Set("Fields[" + 1 + "].IsRequired", "true");

            _formManager.UpdateTemplate(templateViewModel, fieldCollection, fields);

            templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID);
            Assert.IsNotNull(templateViewModel.Fields);
            Assert.AreEqual(1, templateViewModel.Fields.Count);

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();
            Assert.AreEqual(0, templateViewModel.Entries.Count);

            FormCollection submissionCollection = new FormCollection();

            submissionCollection.Add("SubmitFields[1].TextBox", null);

            IDictionary <string, string> submissionFields = new System.Collections.Generic.Dictionary <string, string>();

            submissionFields.Add("1", "1");

            string result = _target.FillIn(submissionFields, templateViewModel, submissionCollection);

            Assert.AreEqual("<ul><li>Click to edit is a required field</li></ul>", result);

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();

            Assert.AreEqual(0, templateViewModel.Entries.Count);
        }
コード例 #4
0
        public void FillIn_NotSelectedConditionFieldWithSubComponentRequiredShouldBeSave()
        {
            FormViewModel formViewModel = new FormViewModel();

            formViewModel.Title = "Required Form Name";
            Template template = _formManager.CreateNewFormAndTemplate(formViewModel);

            Assert.IsNotNull(template);

            TemplateViewModel templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID);

            FormCollection fieldCollection = new FormCollection();
            IDictionary <string, string> fields;

            CeateFieldForm(1, Constants.TemplateFieldType.RADIOBUTTON.ToString(), fieldCollection, out fields);
            fieldCollection.Set("Fields[" + 1 + "].Label", "Radio Button");
            fieldCollection.Set("Fields[" + 1 + "].IsRequired", "true");
            fieldCollection.Add("Fields[" + 1 + "].Options", "Yes,No");

            _formManager.UpdateTemplate(templateViewModel, fieldCollection, fields);

            CeateFieldForm(2, Constants.TemplateFieldType.RADIOBUTTON.ToString(), fieldCollection, out fields);
            fieldCollection.Set("Fields[" + 2 + "].Label", "Radio Button Yes");
            fieldCollection.Set("Fields[" + 2 + "].IsRequired", "true");
            fieldCollection.Add("Fields[" + 2 + "].ConditionTemplateFieldID", "1");
            fieldCollection.Add("Fields[" + 2 + "].ConditionCriteria", "==");
            fieldCollection.Add("Fields[" + 2 + "].ConditionOptions", "Yes");
            fieldCollection.Add("Fields[" + 1 + "].Options", "Yes,No");

            _formManager.UpdateTemplate(templateViewModel, fieldCollection, fields);

            CeateFieldForm(3, Constants.TemplateFieldType.TEXTBOX.ToString(), fieldCollection, out fields);
            fieldCollection.Set("Fields[" + 3 + "].Label", "Radio Button No");
            fieldCollection.Set("Fields[" + 3 + "].IsRequired", "true");
            fieldCollection.Add("Fields[" + 3 + "].ConditionTemplateFieldID", "1");
            fieldCollection.Add("Fields[" + 3 + "].ConditionCriteria", "==");
            fieldCollection.Add("Fields[" + 3 + "].ConditionOptions", "No");

            _formManager.UpdateTemplate(templateViewModel, fieldCollection, fields);

            CeateFieldForm(4, Constants.TemplateFieldType.TEXTBOX.ToString(), fieldCollection, out fields);
            fieldCollection.Set("Fields[" + 4 + "].Label", "Radio Button Yes Yes");
            fieldCollection.Set("Fields[" + 4 + "].IsRequired", "true");
            fieldCollection.Add("Fields[" + 4 + "].ConditionTemplateFieldID", "2");
            fieldCollection.Add("Fields[" + 4 + "].ConditionCriteria", "==");
            fieldCollection.Add("Fields[" + 4 + "].ConditionOptions", "Yes");

            _formManager.UpdateTemplate(templateViewModel, fieldCollection, fields);

            CeateFieldForm(5, Constants.TemplateFieldType.TEXTBOX.ToString(), fieldCollection, out fields);
            fieldCollection.Set("Fields[" + 5 + "].Label", "Radio Button Yes No");
            fieldCollection.Set("Fields[" + 5 + "].IsRequired", "true");
            fieldCollection.Add("Fields[" + 5 + "].ConditionTemplateFieldID", "2");
            fieldCollection.Add("Fields[" + 5 + "].ConditionCriteria", "==");
            fieldCollection.Add("Fields[" + 5 + "].ConditionOptions", "No");

            _formManager.UpdateTemplate(templateViewModel, fieldCollection, fields);

            templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID);
            Assert.IsNotNull(templateViewModel.Fields);
            Assert.AreEqual(5, templateViewModel.Fields.Count);

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();
            Assert.AreEqual(0, templateViewModel.Entries.Count);

            FormCollection submissionCollection = new FormCollection();

            submissionCollection.Add("SubmitFields[1].RadioButton", "Yes");
            submissionCollection.Add("SubmitFields[2].RadioButton", "Yes");
            submissionCollection.Add("SubmitFields[3].TextBox", "i not supposed to be saved 1");
            submissionCollection.Add("SubmitFields[4].TextBox", "Testing 123");
            submissionCollection.Add("SubmitFields[5].TextBox", "i not supposed to be saved 2");

            IDictionary <string, string> submissionFields = new System.Collections.Generic.Dictionary <string, string>();

            submissionFields.Add("1", "1");
            submissionFields.Add("2", "3");
            submissionFields.Add("3", "3");
            submissionFields.Add("4", "4");
            submissionFields.Add("5", "5");

            string result = _target.FillIn(submissionFields, templateViewModel, submissionCollection);

            Assert.AreEqual("success", result);

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();

            Assert.AreEqual(0, _unitOfWork.PreRegistrations.GetAll().Count());

            Assert.AreEqual(3, templateViewModel.Entries.Count);

            Assert.AreEqual("Yes", templateViewModel.Entries[0].Value);
            Assert.AreEqual("Yes", templateViewModel.Entries[1].Value);
            Assert.AreEqual("Testing 123", templateViewModel.Entries[2].Value);
        }
コード例 #5
0
        public ActionResult SaveGridData(object id, FormCollection collection)
        {
            string    sidx = TempData["id"] as string;
            DataTable Dt   = TempData["data"] as DataTable;

            int    DHeaderID = Convert.ToInt32(HttpContext.Request.Url.Segments.Last());
            string vType     = HttpContext.Request.UrlReferrer.Segments.Last();

            Dal.TFAT_WEBERPEntities ctx   = new Dal.TFAT_WEBERPEntities();
            Dal.TfatDesignHeader    DHead = ctx.TfatDesignHeaders.First(h => h.HeaderRecordKey == DHeaderID);

            string[] IDs    = DHead.IDKey.Split(new char[] { '^' });
            string   IDkeys = IDs.Count() > 1 ? IDs.Last() : IDs.First();
            object   result;

            if (vType.ToUpper().ToString() == "GRID")
            {
                switch (collection["oper"].ToUpper())
                {
                case "ADD":
                    collection.Remove("oper");
                    collection.Remove("id");
                    FormCollection fcoll1 = mIBusi.GetDBFormCollection(DHead, collection);
                    fcoll1.Set(IDkeys, "");
                    DynAdd.DynamicAddMaster(DHeaderID, fcoll1);
                    break;

                case "EDIT":
                    collection.Remove("oper");
                    FormCollection fcoll2 = mIBusi.GetDBFormCollection(DHead, collection);
                    fcoll2.Set(IDkeys, collection["id"]);
                    //collection.Remove("id");
                    DynEdit.DynamicEditMaster(DHeaderID, fcoll2);
                    break;

                case "DEL":
                    collection.Remove("oper");
                    FormCollection fcoll3 = mIBusi.GetDBFormCollection(DHead, collection);
                    fcoll3.Set(IDkeys, collection["id"]);
                    //collection.Remove("id");
                    DynDel.DynamicDeleteMaster(DHeaderID, fcoll3);
                    break;
                }
                result = GrdOper.Get(IDkeys, "asc", 1, 100);
            }
            else
            {
                switch (collection["oper"].ToUpper())
                {
                case "ADD":
                    collection.Remove("oper");
                    collection.Remove("id");
                    DynAdd.DynamicGirdAddMaster(DHeaderID, collection, Dt);
                    break;

                case "EDIT":
                    collection.Remove("oper");
                    collection.Set(IDkeys, collection["id"]);
                    collection.Remove("id");
                    DynEdit.DynamicGirdEditMaster(DHeaderID, collection, Dt);
                    break;

                case "DEL":
                    collection.Remove("oper");
                    collection.Set(IDkeys, collection["id"]);
                    collection.Remove("id");
                    DynDel.DynamicGirdDeleteMaster(DHeaderID, collection, Dt);
                    break;
                }
                //int mid = collection[IDkeys].ToString() == string.Empty ? 0 : int.Parse(collection[IDkeys].ToString());
                result          = GrdOper.Get(IDkeys, "asc", 1, 100, ref Dt);
                Session["data"] = Dt;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public string processExcel(HttpPostedFileBase file)
        {
            int readData = 0;
            //data for service
            FormCollection formCollection = new FormCollection();

            //process
            try
            {
                IWorkbook     wb    = new XSSFWorkbook(file.InputStream);
                ISheet        sheet = wb.GetSheetAt(wb.ActiveSheetIndex);
                List <string> keys  = new List <string>
                {
                    "child-ch-name",
                    "child-fname",
                    "child-name",
                    "child-birth",
                    "child-gender",
                    "child-class",
                    "child-address",
                    "fa-ch-name",
                    "fa-fname",
                    "fa-name",
                    "fa-phone",
                    "mo-ch-name",
                    "mo-fname",
                    "mo-name",
                    "mo-phone"
                };
                //
                int   count = 0;
                IRow  row;
                ICell cell;
                for (int rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++)
                {
                    row = sheet.GetRow(rowIndex);
                    for (int cellIndex = 0; cellIndex < row.LastCellNum; cellIndex++)
                    {
                        try
                        {
                            cell = row.GetCell(cellIndex);
                            cell.SetCellType(CellType.String);
                            formCollection.Set(keys[count], cell.StringCellValue);
                        }
                        catch (Exception)
                        {
                            formCollection.Set(keys[count], "");
                        }
                        count++;
                    }
                    formCollection.Set("child-role", "4");
                    using (PersonService personService = new PersonService())
                    {
                        Response res = personService.addPerson(formCollection);
                        if (res.success)
                        {
                            readData++;
                        }
                    }
                    //clear before add new record
                    count = 0;
                    formCollection.Clear();
                }
            }
            catch (Exception e)
            {
                return("ERROR" + e.Message);
            }
            return("Processed " + readData + " records");
        }