예제 #1
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Option option = new Option();
                option.Name        = AddOptionName.Text;
                option.CreatedDate = LocaleHelper.LocalNow;

                string[] choices = AddOptionChoices.Text.Split(",".ToCharArray());
                foreach (string item in choices)
                {
                    string choiceName = item.Trim();
                    if (choiceName != String.Empty)
                    {
                        OptionChoice choice = new OptionChoice();
                        choice.Option  = option;
                        choice.Name    = StringHelper.Truncate(choiceName, 50);
                        choice.OrderBy = -1;
                        option.Choices.Add(choice);
                    }
                }
                option.Save();
                ProductOption productOption = new ProductOption(_Product, option, -1);
                productOption.Save();

                // RESET VARIANT GRID FOR THE ASSOCIATED PRODUCT
                ProductVariantManager.ResetVariantGrid(_Product.Id);
                option.ProductOptions.Add(productOption);
                _Options.Add(option);
                AddOptionName.Text    = string.Empty;
                AddOptionChoices.Text = string.Empty;
                BindOptionsGrid();
            }
        }
예제 #2
0
 private OptionChoiceEntity(string description, string imageFullName, OptionChoice option, bool taken = false)
 {
     _pcs           = new PropertyChangeSupport(this);
     _optionChoice  = option;
     _imageFullPath = imageFullName;
     _taken         = taken;
 }
예제 #3
0
 public ActionResult DeleteConfirmed(int id)
 {
     OptionChoice optionChoice = db.dbOptionChoices.Find(id);
     db.dbOptionChoices.Remove(optionChoice);
     db.SaveChanges();
     return RedirectToAction("Index");
 }
예제 #4
0
        public Product Get(int id)
        {
            var product = new Product
            {
                Id          = id,
                ProductName = "Car"
            };
            var option = new Option()
            {
                OptionName = "Color",
                ProductId  = product.Id
            };

            product.Options = new Collection <Option>();
            product.Options.Add(option);

            var optionChoice = new OptionChoice()
            {
                OptionChoiceName = "Blue",
                OptionId         = option.Id
            };

            option.OptionChoices = new Collection <OptionChoice>();
            option.OptionChoices.Add(optionChoice);

            return(product);
        }
예제 #5
0
        private static async Task _updateOptionChoices(IList <OptionChoice> trackedOptionChoices, IList <OptionChoice> newOptionsChoices, ResotelContext ctx)
        {
            // Deletion ain't no small thing in EF, that thing holds memory dear,
            // so once you delete something, all aggregated entities are set to null, fun, isn't it
            // db do have transactions to test and try things before committing, but EF does not ..
            // cancelling a deletion imply a new db request, how sweet
            List <OptionChoice> optionChoicesToRemove = trackedOptionChoices.
                                                        Where(trackedOptC => !newOptionsChoices.Any(newOptC => newOptC.Id == trackedOptC.Id)).ToList();

            _removeExistingOptionChoices(optionChoicesToRemove, ctx);

            foreach (OptionChoice optChoice in newOptionsChoices)
            {
                OptionChoice trackedOptChoice = await _getTrackedOptionChoice(optChoice, ctx);
                await _getTrackedOption(optChoice, ctx);

                DateRange trackedOptDates = await _getTrackedOptionDates(optChoice, ctx);


                _updateTrackedOptionDates(trackedOptDates, optChoice.TakenDates, ctx);
                _updateTrackedOptionChoice(trackedOptChoice, optChoice, ctx);

                trackedOptionChoices.Add(trackedOptChoice);
            }
        }
예제 #6
0
 private static void _removeExistingOptionChoices(IList <OptionChoice> trackedOptionChoices, ResotelContext ctx)
 {
     for (int i = trackedOptionChoices.Count - 1; i >= 0; i--)
     {
         OptionChoice trackedOptChoice = trackedOptionChoices[i];
         ctx.Entry(trackedOptChoice).State = EntityState.Deleted;
     }
 }
 public OptionChoiceViewModel(OptionChoice optionChoice)
 {
     Id = optionChoice.Id;
     OptionChoiceName         = optionChoice.OptionChoiceName;
     OptionChoiceCode         = optionChoice.OptionChoiceCode;
     OptionChoicePrice        = optionChoice.OptionChoicePrice;
     OptionChoiceDeliveryDate = optionChoice.OptionChoiceDeliveryDate;
     IsCheckedOptionChoice    = optionChoice.IsCheckedOptionChoice;
 }
예제 #8
0
        private static async Task <DateRange> _getTrackedOptionDates(OptionChoice optChoice, ResotelContext ctx)
        {
            DateRange trackedOptDates = await ctx.Set <DateRange>().FirstOrDefaultAsync(dr => dr.Id == optChoice.TakenDates.Id);

            if (trackedOptDates == null)
            {
                trackedOptDates = ctx.Set <DateRange>().Add(optChoice.TakenDates);
            }

            return(trackedOptDates);
        }
예제 #9
0
        public OptionChoiceEntity(OptionChoice optionChoice)
        {
            _pcs          = new PropertyChangeSupport(this);
            _optionChoice = optionChoice;

            string cleanedLabel;

            cleanedLabel   = _cleanLabel(optionChoice.Option.Label);
            _imageFullPath = string.Format("/Resources/{0}.png", cleanedLabel);
            _taken         = false;
        }
예제 #10
0
 public ActionResult Edit([Bind(Include = "Id,OptionChoiceName,OptionChoiceCode,OptionChoicePrice,OptionChoiceDeliveryDate,OptionId")] OptionChoice optionChoice)
 {
     if (ModelState.IsValid)
     {
         db.Entry(optionChoice).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.OptionId = new SelectList(db.dbOptions, "Id", "OptionName", optionChoice.OptionId);
     return View(optionChoice);
 }
예제 #11
0
 // GET: AdminOptionChoices/Delete/5
 public ActionResult Delete(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     OptionChoice optionChoice = db.dbOptionChoices.Find(id);
     if (optionChoice == null)
     {
         return HttpNotFound();
     }
     return View(optionChoice);
 }
예제 #12
0
 public bool AddOptionChoice(OptionChoice option)
 {
     try
     {
         db.OptionChoices.Add(option);
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #13
0
 // GET: AdminOptionChoices/Edit/5
 public ActionResult Edit(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     OptionChoice optionChoice = db.dbOptionChoices.Find(id);
     if (optionChoice == null)
     {
         return HttpNotFound();
     }
     ViewBag.OptionId = new SelectList(db.dbOptions, "Id", "OptionName", optionChoice.OptionId);
     return View(optionChoice);
 }
예제 #14
0
        private static async Task <OptionChoice> _getTrackedOptionChoice(OptionChoice optChoice, ResotelContext ctx)
        {
            OptionChoice trackedOptChoice = await ctx.Set <OptionChoice>()
                                            .Include(optC => optC.Option)
                                            .Include(optC => optC.Option.Discounts)
                                            .Include(optC => optC.Option.Rooms)
                                            .Include(optC => optC.TakenDates)
                                            .FirstOrDefaultAsync(optC => optC.Id == optChoice.Id);

            if (trackedOptChoice == null)
            {
                trackedOptChoice = ctx.Set <OptionChoice>().Add(optChoice);
            }

            return(trackedOptChoice);
        }
예제 #15
0
        private static void _setAvailableOptionChoiceEntities(Booking booking, DateRange dates, OptionsViewModel newInstance, List <Option> availableOptions)
        {
            foreach (Option opt in availableOptions)
            {
                OptionChoice optChoice = new OptionChoice
                {
                    Option     = opt,
                    TakenDates = (DateRange)((ICloneable)dates).Clone()
                };
                optChoice.TakenDates.Start = optChoice.TakenDates.Start.Date;

                if (optChoice.Option.Id == 8)
                {
                    optChoice.TakenDates.Start = optChoice.TakenDates.Start.AddDays(1.0d);
                }

                OptionChoiceEntity optChoiceEntity = new OptionChoiceEntity(booking, optChoice);
                newInstance._availableOptionChoiceEntities.Add(optChoiceEntity);
            }
        }
예제 #16
0
        protected void AddChoiceButton_Click(object sender, EventArgs e)
        {
            OptionChoice choice = new OptionChoice();

            choice.Option         = _Option;
            choice.Name           = AddChoiceName.Text;
            choice.ThumbnailUrl   = AddChoiceThumbnail.Text;
            choice.ImageUrl       = AddChoiceImage.Text;
            choice.PriceModifier  = AlwaysConvert.ToDecimal(AddChoicePriceMod.Text);
            choice.MsrpModifier   = AlwaysConvert.ToDecimal(AddChoiceRetialMod.Text);
            choice.WeightModifier = AlwaysConvert.ToDecimal(AddChoiceWeightMod.Text);
            choice.SkuModifier    = AddChoiceSkuMod.Text.Trim();
            choice.OrderBy        = -1;
            choice.Selected       = Selected.Checked;

            // MAKE SURE ONLY ONE CHOICE IS SELECTED
            if (Selected.Checked)
            {
                foreach (OptionChoice existingChoice in _Option.Choices)
                {
                    if (existingChoice.Selected)
                    {
                        existingChoice.Selected = false;
                    }
                }
            }

            _Option.Choices.Add(choice);
            _Option.Save();

            BindChoicesGrid();
            AddChoiceName.Text      = string.Empty;
            AddChoiceThumbnail.Text = string.Empty;
            AddChoiceImage.Text     = string.Empty;
            AddChoicePriceMod.Text  = string.Empty;
            AddChoiceRetialMod.Text = string.Empty;
            AddChoiceWeightMod.Text = string.Empty;
            AddChoiceSkuMod.Text    = string.Empty;
            SavedMessage.Visible    = true;
        }
예제 #17
0
        public OptionChoiceEntity(Booking booking, OptionChoice optionChoice)
        {
            _pcs          = new PropertyChangeSupport(this);
            _optionChoice = optionChoice;
            _booking      = booking;


            string cleanedLabel;

            if (optionChoice != null)
            {
                cleanedLabel   = _cleanLabel(optionChoice.Option.Label);
                _imageFullPath = string.Format("/Resources/{0}.png", cleanedLabel);

                // restauration
                if (optionChoice.PeopleCount == 0 && optionChoice.Option.Id == 8)
                {
                    PeopleCount = 1;
                }
            }
            _taken = false;
        }
예제 #18
0
        protected virtual void RenderMenu(IList <OptionChoice> optionChoices, OptionChoice currentlySelectedOption, RenderContext context)
        {
            foreach (var option in optionChoices)
            {
                if (currentlySelectedOption == option)
                {
                    Console.ForegroundColor = context.ColorFor(ColorType.SpecialTextHighlightForeground);
                    Console.BackgroundColor = context.ColorFor(ColorType.SpecialTextHighlightBackground);
                    Console.Write("> ");
                }
                else
                {
                    Console.ForegroundColor = context.ColorFor(ColorType.SpecialTextForeground);
                    Console.BackgroundColor = context.ColorFor(ColorType.SpecialTextBackground);
                    Console.Write("  ");
                }

                Console.Write($"{option.Title} [{option.Id}]");
                Console.ForegroundColor = context.ColorFor(ColorType.NormalTextForeground);
                Console.BackgroundColor = context.ColorFor(ColorType.NormalTextBackground);
                Console.Write("\n");
            }
        }
예제 #19
0
 private static async Task _getTrackedOption(OptionChoice optChoice, ResotelContext ctx)
 {
     Option trackedOpt = await ctx.Options.FirstOrDefaultAsync(opt => opt.Id == optChoice.Id);
 }
예제 #20
0
 private static void _updateTrackedOptionChoice(OptionChoice trackedOptChoice, OptionChoice newOptChoice, ResotelContext ctx)
 {
     ctx.Entry(trackedOptChoice).CurrentValues.SetValues(newOptChoice);
 }
예제 #21
0
        protected override void Render(HtmlTextWriter output)
        {
            StringBuilder html = new StringBuilder();

            if (this.RenderOptions)
            {
                if (_Option != null)
                {
                    int productId = 0;
                    if (_Option.ProductOptions.Count > 0)
                    {
                        productId = _Option.ProductOptions[0].ProductId;
                    }
                    OptionChoiceCollection availableChoices = null;
                    if (ForceToLoadAllChoices)
                    {
                        availableChoices = _Option.Choices;
                    }
                    else
                    {
                        availableChoices = OptionChoiceDataSource.GetAvailableChoices(productId, _Option.OptionId, _SelectedChoices);
                    }
                    if (availableChoices.Count > 0)
                    {
                        //ADD REQUIRED STYLING FOR SWATCH
                        //SET THE HEIGHT AND WIDTH
                        html.Append("<style>\n");
                        html.Append("     ." + this.ClientID + " td { padding:0px !important;width:" + _Option.ActiveThumbnailWidth + "px;height:" + _Option.ActiveThumbnailHeight + "px;cursor:pointer; }\n");
                        html.Append("</style>\n");
                        html.Append("<div class=\"" + this.ClientID);
                        if (!string.IsNullOrEmpty(this.CssClass))
                        {
                            html.Append(" " + this.CssClass);
                        }
                        html.Append("\">\n");

                        //OUTPUT THE CURRENT SELECTION
                        html.Append("<span id=\"" + this.ClientID + "Text\">");
                        OptionChoice selOpt = GetSelectedChoice(availableChoices);
                        if (selOpt != null)
                        {
                            html.Append(selOpt.Name);
                        }
                        html.Append("</span>\n");

                        //OUTPUT THE SWATCH PICKER
                        html.Append("     <table cellpadding=\"0\" cellspacing=\"2\" onclick=\"javascript:OptionPickerClick(event, '" + this.ClientID + "');");
                        if (this.AutoPostBack)
                        {
                            PostBackOptions options = new PostBackOptions(this, string.Empty);
                            options.AutoPostBack = true;
                            html.Append(this.Page.ClientScript.GetPostBackEventReference(options, true));
                        }
                        html.Append("\">\n");
                        for (int i = 0; i < availableChoices.Count; i++)
                        {
                            if (i % _Option.ActiveThumbnailColumns == 0)
                            {
                                if (i > 0)
                                {
                                    html.Append("            </tr>\n");
                                }
                                html.Append("            <tr>\n");
                            }
                            OptionChoice choice = availableChoices[i];
                            html.Append("                <td");
                            if (choice.OptionChoiceId == this.SelectedChoiceId)
                            {
                                html.Append(" class=\"selected\"");
                            }
                            html.Append(" title=\"" + HttpUtility.HtmlEncode(choice.Name) + "\"");
                            html.Append(" style=\"background-image:url(" + this.Page.ResolveUrl(choice.ThumbnailUrl) + ");z-index:" + choice.OptionChoiceId.ToString() + "\">&nbsp;</td>\n");
                        }
                        html.Append("            </tr>\n");
                        html.Append("     </table>\n");
                        html.Append("</div>\n");
                    }
                    else
                    {
                        html.Append("(no options available)");
                    }
                    html.Append("<input type=\"hidden\" id=\"" + this.ClientID + "\" name=\"" + this.UniqueID + "\" value=\"" + this.SelectedChoiceId.ToString() + "\">\n");
                }
                else
                {
                    WebTrace.Write(this.UniqueID, "Invalid Option " + this.OptionId.ToString());
                }
            }
            output.Write(html.ToString());
        }
예제 #22
0
        // GET: NewSurvey
        public JsonResult CreateSurvey(string dataSurvey)
        {
            JObject obj = JObject.Parse(dataSurvey);
            ///////
            Survey survey = services.ConvertJsonToObject(obj);

            services.AddSurvey(survey);
            SubUserSurvey subSurvey = new SubUserSurvey();

            subSurvey.IdSurvey = survey.Id;
            subSurvey.IdUser   = services.GetIdUser((string)obj["username"]);
            services.AddSubSurvey(subSurvey);
            ////// create survey

            //////
            List <Section> ListSection        = new List <Section>();
            JArray         listJArrayInfoPage = (JArray)obj["infoListPage"];
            List <int>     ListInfoPage       = new List <int>();
            List <string>  EmailShare         = new List <string>();
            int            i = 0;

            foreach (JValue value in listJArrayInfoPage)
            {
                Section tempSection = new Section();
                tempSection.SurveyId      = survey.Id;
                tempSection.NumberSection = i;
                services.AddSection(tempSection);//add record section
                ListSection.Add(tempSection);
                var values = value.ToObject <int>();
                ListInfoPage.Add(values);
                i++;
            }
            ////////
            List <Question> ListQuestion       = new List <Question>();
            JArray          listJArrayQuestion = (JArray)obj["listQuestion"];

            i = 0;
            foreach (JObject value in listJArrayQuestion)
            {
                Question tempQuestion = new Question();
                tempQuestion.Contents       = (string)value["titleQuestion"];
                tempQuestion.IsRequired     = (bool)value["required"];
                tempQuestion.NumberQuestion = i;
                tempQuestion.QuestionTypeId = services.GetIdQuestionType((string)value["typeQuestion"]);
                i++;
                int dem = 0;
                for (int j = 0; j < ListInfoPage.Count; j++)
                {
                    dem = dem + ListInfoPage[j];
                    if (tempQuestion.NumberQuestion < dem)
                    {
                        tempQuestion.SectionId = ListSection[j].Id;
                        services.AddQuestion(tempQuestion);
                        break;
                    }
                }

                List <OptionChoice> ListOptionChoice = new List <OptionChoice>();
                if ((string)value["typeQuestion"] == "MultipleChoice" || (string)value["typeQuestion"] == "CheckBoxs" ||
                    (string)value["typeQuestion"] == "Dropdown")
                {
                    foreach (JValue itemOption in (JArray)value["listQuestionOption"])
                    {
                        OptionChoice tempOptionChoice = new OptionChoice();
                        tempOptionChoice.Contents = itemOption.ToObject <string>();
                        ListOptionChoice.Add(tempOptionChoice);
                        services.AddOptionChoice(tempOptionChoice);// create record questionOption
                        QuestionOption tempQuestionOption = new QuestionOption();
                        tempQuestionOption.OptionChoiceId = tempOptionChoice.Id;
                        tempQuestionOption.QuestionId     = tempQuestion.Id;
                        services.AddQuestionOption(tempQuestionOption);
                    }
                }
                if ((string)value["typeQuestion"] == "LinearScale")
                {
                    OptionChoice tempOptionChoice = new OptionChoice();
                    tempOptionChoice.MinimumOflinearScale     = (int)value["min"];
                    tempOptionChoice.MaximumOflinearScale     = (int)value["max"];
                    tempOptionChoice.ChoiceValueOflinearScale = (int)value["choiceLinear"];
                    services.AddOptionChoice(tempOptionChoice);// create record questionOption
                    QuestionOption tempQuestionOption = new QuestionOption();
                    tempQuestionOption.OptionChoiceId = tempOptionChoice.Id;
                    tempQuestionOption.QuestionId     = tempQuestion.Id;
                    services.AddQuestionOption(tempQuestionOption);
                }
            }



            ////Create section for survey

            foreach (JValue value in (JArray)obj["mailShare"])
            {
                var values = value.ToObject <string>();
                EmailShare.Add(values);
            }



            return(Json(survey.Id, JsonRequestBehavior.AllowGet));
        }