public ActionResult CreateEdit(CustomerSurvey customersurvey)
        {
            if (ModelState.IsValid)
            {
                //If No ID => ADD
                if (customersurvey.surveyId <= 0)
                {
                    db.CustomerSurveys.Add(customersurvey);
                }
                //IF there is ID => Update
                else
                {
                    db.Entry(customersurvey).State = EntityState.Modified;
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var students = db.UserAccounts.Where(x => !x.isTeacher).ToList();
            var teachers = db.UserAccounts.Where(x => x.isTeacher).ToList();

            ViewBag.customerId       = new SelectList(db.Customers, "customerId", "companyName", customersurvey.customerId);
            ViewBag.baseSurveyId     = new SelectList(db.GenericSurveys, "surveyId", "title", customersurvey.baseSurveyId);
            ViewBag.observerUserId   = new SelectList(students, "userId", "userName", customersurvey.observerUserId);
            ViewBag.supervisorUserId = new SelectList(teachers, "userId", "userName", customersurvey.supervisorUserId);
            return(View(customersurvey));
        }
        public ActionResult Details(int id = 0)
        {
            CustomerSurvey customersurvey = db.CustomerSurveys.Find(id);

            if (customersurvey == null)
            {
                return(HttpNotFound());
            }

            //Additional Info For Sidebar
            var surveyReport = customersurvey.CustomerAnswers;

            int questionsAmount   = customersurvey.GenericSurvey.Questions.Count;
            int questionsAnswered = surveyReport.Count;

            ViewBag.AnsweredQuestions = String.Format("{0} / {1}", questionsAnswered, questionsAmount);

            double avgObserverStatus = (surveyReport.Average(x => x.observerStatusValue)) ?? 0;

            ViewBag.AverageObserverStatus = Math.Round(avgObserverStatus, 2);

            /* Factor here derrives from AnswerStatusValue Range.
             * Minima = 0, Maxima = 4 --> Four answers with value 4 should give 100 %
             * --> 16/4 * factor = 100 % --> factor = 25 */
            int    factor             = 25;
            double averageAnswerValue = (surveyReport.Average(z => z.answerStatusValue)) ?? 0;
            int    surveyProgress     = (int)Math.Round(averageAnswerValue * factor);

            ViewBag.SurveyProgress = String.Format("{0}%", surveyProgress);

            return(View(customersurvey));
        }
예제 #3
0
 public TaxInformationResponse Process(CustomerSurvey customerSurvey)
 {
     if (customerSurvey.Salary >= 100000)
     {
         return(_yesDecisionChain.Process(customerSurvey));
     }
     return(_noDecisionChain.Process(customerSurvey));
 }
 public TaxInformationResponse Process(CustomerSurvey customerSurvey)
 {
     if (customerSurvey.Maritalstatus == MaritalStatus.Married)
     {
         return(_yesDecisionChain.Process(customerSurvey));
     }
     return(_noDecisionChain.Process(customerSurvey));
 }
예제 #5
0
 public TaxInformationResponse Process(CustomerSurvey customerSurvey)
 {
     if (customerSurvey.Country == "USA")
     {
         return(_yesDecisionChain.Process(customerSurvey));
     }
     return(_noDecisionChain.Process(customerSurvey));
 }
예제 #6
0
        public void Junior_CantAdd_DebitCard_Test()
        {
            var customer = new Customer {
                AccountType = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value), CustomerName = "Junior2"
            };

            _customerRepository.Add(customer);
            var survey   = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2);
            var custSurv = new CustomerSurvey
            {
                CustomerId = customer.Id,
                SurveyId   = survey.Id,
                Date       = DateTime.Now
            };

            _customerSurveyRepository.Add(custSurv);
            var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value);              //Age?
            var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_0_17.Value); //"0-17"
            var answerAge   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id
            };

            _answerRepository.Add(answerAge);
            var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);;   //Is Student?
            var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.No.Value); //"no"
            var answerStud   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id
            };

            _answerRepository.Add(answerStud);
            var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value);           //Income?
            var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_0.Value); //"0"
            var answerIncome   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id
            };

            _answerRepository.Add(answerIncome);

            var    bundleRecomemndation = new BundleRecomendationService(_context);
            Bundle recomendeBundle      = bundleRecomemndation.Recommend(customer, survey);

            var    debitCard     = _productRepository.GetByName(Product.DebitCard.Value);
            var    prodSelection = new ProducSelectionService(_context);
            string msg;
            var    res = prodSelection.IsCanAddProduct(debitCard, customer, survey, out msg);

            _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} \tValue: {recomendeBundle?.Value}");
            foreach (var productBundle in recomendeBundle?.ProductIncluded)
            {
                _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}");
            }
            _output.WriteLine($"\tres: [{res}], Msg: [{msg}]");
            Assert.False(res);
            Assert.Equal("Age not hits", msg);
        }
예제 #7
0
        public void Student_CantAdd_CreditCard_WithBigIncome_Test()
        {
            var customer = new Customer {
                AccountType = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value), CustomerName = "Student adds credit card, income 12001-40000"
            };

            _customerRepository.Add(customer);
            var survey   = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2);
            var custSurv = new CustomerSurvey
            {
                CustomerId = customer.Id,
                SurveyId   = survey.Id,
                Date       = DateTime.Now
            };

            _customerSurveyRepository.Add(custSurv);
            var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value);//Age?
            var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_18_64.Value);
            var answerAge   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id
            };

            _answerRepository.Add(answerAge);
            var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);; //Is Student?
            var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Yes.Value);
            var answerStud   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id
            };

            _answerRepository.Add(answerStud);
            var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value);//Income?
            var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_12001_40000.Value);
            var answerIncome   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id
            };

            _answerRepository.Add(answerIncome);

            var    bundleRecomemndation = new BundleRecomendationService(_context);
            Bundle recomendeBundle      = bundleRecomemndation.Recommend(customer, survey);

            var card          = _productRepository.GetByName(Product.CreditCard.Value);
            var prodSelection = new ProducSelectionService(_context);

            var ex = Assert.Throws <CantAddExcption>(() => prodSelection.AddProductToBundle(recomendeBundle, card, customer, survey));

            _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} \tValue: {recomendeBundle?.Value}");
            foreach (var productBundle in recomendeBundle?.ProductIncluded)
            {
                _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}");
            }
            //_output.WriteLine($"\tres: [{res}], Msg: [{msg}]");
            //Assert.False(res);
            Assert.Equal("Stud not hits", ex.Message);
        }
예제 #8
0
        public void Junior_Add_JuniorAccount_Test()
        {
            var customer = new Customer {
                AccountType = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value), CustomerName = "Junior2"
            };

            _customerRepository.Add(customer);
            var survey   = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2);
            var custSurv = new CustomerSurvey
            {
                CustomerId = customer.Id,
                SurveyId   = survey.Id,
                Date       = DateTime.Now
            };

            _customerSurveyRepository.Add(custSurv);
            var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value);              //Age?
            var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_0_17.Value); //"0-17"
            var answerAge   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id
            };

            _answerRepository.Add(answerAge);
            var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);;   //Is Student?
            var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.No.Value); //"no"
            var answerStud   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id
            };

            _answerRepository.Add(answerStud);
            var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value);           //Income?
            var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_0.Value); //"0"
            var answerIncome   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id
            };

            _answerRepository.Add(answerIncome);

            var    bundleRecomemndation = new BundleRecomendationService(_context);
            Bundle recomendeBundle      = bundleRecomemndation.Recommend(customer, survey);

            var product       = _productRepository.GetByName(Product.JuniorSaverAccount.Value);
            var prodSelection = new ProducSelectionService(_context);

            var ex = Assert.Throws <CantAddExcption>(() => prodSelection.AddProductToBundle(recomendeBundle, product, customer, survey));

            _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} \tValue: {recomendeBundle?.Value}");
            foreach (var productBundle in recomendeBundle?.ProductIncluded)
            {
                _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}");
            }
            //_output.WriteLine($"\tres: [{res}]");
            Assert.Equal("Item allready exists", ex.Message);
        }
예제 #9
0
        public void more40kIncomeTest()
        {
            var customerName = "Customer with more than 40k income";
            var customer     = new Customer {
                AccountType = _accountTypeRepository.GetAccountTypeById(1), CustomerName = customerName
            };

            _customerRepository.Add(customer);
            var survey   = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2);
            var custSurv = new CustomerSurvey
            {
                CustomerId = customer.Id,
                SurveyId   = survey.Id,
                Date       = DateTime.Now
            };

            _customerSurveyRepository.Add(custSurv);
            var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value);               //Age?
            var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_18_64.Value); //"18-64"
            var answerAge   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id
            };

            _answerRepository.Add(answerAge);
            var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);;   //Is Student?
            var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.No.Value); //"no"
            var answerStud   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id
            };

            _answerRepository.Add(answerStud);
            var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value);                   //Income?
            var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_40001plus.Value); //"40000+"
            var answerIncome   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id
            };

            _answerRepository.Add(answerIncome);

            var    bundleRecomemndation = new BundleRecomendationService(_context);
            Bundle recomendeBundle      = bundleRecomemndation.Recommend(customer, survey);

            _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} Value: {recomendeBundle?.Value}");
            Assert.Equal("Gold", recomendeBundle?.BundleName);
            foreach (var productBundle in recomendeBundle?.ProductIncluded)
            {
                _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}");
            }
        }
예제 #10
0
        public void JuniorTest()
        {
            var customer = new Customer
            {
                //Id = 99,
                AccountType  = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value),
                CustomerName = "Junior1"
            };

            _customerRepository.Add(customer);
            var survey   = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2);
            var custSurv = new CustomerSurvey
            {
                CustomerId = customer.Id,
                SurveyId   = survey.Id,
                Date       = DateTime.Now
            };

            _customerSurveyRepository.Add(custSurv);
            var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value);              //Age?
            var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_0_17.Value); //"0-17"
            var answerAge   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id
            };

            _answerRepository.Add(answerAge);
            var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);;   //Is Student?
            var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.No.Value); //"no"
            var answerStud   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id
            };

            _answerRepository.Add(answerStud);
            var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value);           //Income?
            var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_0.Value); //"0"
            var answerIncome   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id
            };

            _answerRepository.Add(answerIncome);

            var    bundleRecomemndation = new BundleRecomendationService(_context);
            Bundle recomendeBundle      = bundleRecomemndation.Recommend(customer, survey);

            _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} Value: {recomendeBundle?.Value}");
            Assert.Equal(Bundle.JuniorSaver.Value, recomendeBundle?.BundleName);
            _output.WriteLine($"\tIncluded Product: {recomendeBundle?.ProductIncluded?.FirstOrDefault().Product.ProductName}");
            Assert.Equal(Product.JuniorSaverAccount.Value, recomendeBundle?.ProductIncluded?.FirstOrDefault().Product.ProductName);
        }
        public ActionResult Edit(int id = 0)
        {
            CustomerSurvey customersurvey = db.CustomerSurveys.Find(id);

            if (customersurvey == null)
            {
                return(HttpNotFound());
            }
            var students = db.UserAccounts.Where(x => !x.isTeacher).ToList();

            ViewBag.customerId     = new SelectList(db.Customers, "customerId", "companyName", customersurvey.customerId);
            ViewBag.baseSurveyId   = new SelectList(db.GenericSurveys, "surveyId", "title", customersurvey.baseSurveyId);
            ViewBag.observerUserId = new SelectList(students, "userId", "userName", customersurvey.observerUserId);
            return(View("CreateEdit", customersurvey));
        }
예제 #12
0
        private void GetSurveyControl(string usercontrol)
        {
            switch (usercontrol)
            {
            case "PCPromoSurvey":
                PCPromoSurvey pccontrol = (PCPromoSurvey)LoadControl("Controls/Survey/PCPromoSurvey.ascx");
                PlaceHolder1.Controls.Add(pccontrol);
                break;

            case "CustomerSurvey":
                CustomerSurvey cscontrol = (CustomerSurvey)LoadControl("Controls/Survey/CustomerSurvey.ascx");
                PlaceHolder1.Controls.Add(cscontrol);
                break;
            }
        }
        public ActionResult Delete(int id = 0)
        {
            CustomerSurvey customersurvey = db.CustomerSurveys.Find(id);

            if (customersurvey == null)
            {
                return(HttpNotFound());
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(customersurvey));
            }

            return(View(customersurvey));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CustomerSurvey customersurvey = db.CustomerSurveys.Find(id);
            bool           credentials    = customersurvey.UserAccount1.userName == User.Identity.Name;

            if (credentials)
            {
                var customerAnswersList = customersurvey.CustomerAnswers.ToList();
                foreach (var item in customerAnswersList)
                {
                    db.CustomerAnswers.Remove(item);
                }
                db.CustomerSurveys.Remove(customersurvey);

                db.SaveChanges();
            }
            else
            {
                TempData["Message"] = "Only the supervising teacher may delete this survey.";
            }

            return(RedirectToAction("Index"));
        }
예제 #15
0
        public void Classic_CanAdd_CreditCard_Test()
        {
            var customer = new Customer {
                AccountType = _accountTypeRepository.GetAccountTypeByName(AccountType.CurrentAccount.Value), CustomerName = "Customer adds credit card"
            };

            _customerRepository.Add(customer);
            var survey   = _surveyRepository.GetAll().FirstOrDefault(s => s.Title == Survey.FirstSurvey.Item2);
            var custSurv = new CustomerSurvey
            {
                CustomerId = customer.Id,
                SurveyId   = survey.Id,
                Date       = DateTime.Now
            };

            _customerSurveyRepository.Add(custSurv);
            var ageQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Age.Value);//Age?
            var selectedAge = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Age_18_64.Value);
            var answerAge   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = ageQuestion.Id, SelectedAnswerId = selectedAge.Id
            };

            _answerRepository.Add(answerAge);
            var studQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Student.Value);; //Is Student?
            var selectedStud = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.No.Value);
            var answerStud   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = studQuestion.Id, SelectedAnswerId = selectedStud.Id
            };

            _answerRepository.Add(answerStud);
            var incomeQuestion = _questionRepository.GetAll().FirstOrDefault(q => q.QuestionText == Question.Income.Value);//Income?
            var selectedIncome = _possibleAnswersRepository.GetAll().FirstOrDefault(pa => pa.Text == PossibleAnswers.Income_12001_40000.Value);
            var answerIncome   = new Answer {
                CustomerId = customer.Id, SurveyId = survey.Id, QuestionId = incomeQuestion.Id, SelectedAnswerId = selectedIncome.Id
            };

            _answerRepository.Add(answerIncome);

            var    bundleRecomemndation = new BundleRecomendationService(_context);
            Bundle recomendeBundle      = bundleRecomemndation.Recommend(customer, survey);

            _output.WriteLine($"Recomended Bundle: {recomendeBundle?.BundleName} \tValue: {recomendeBundle?.Value}");
            foreach (var productBundle in recomendeBundle?.ProductIncluded)
            {
                _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}");
            }

            var card          = _productRepository.GetByName(Product.CreditCard.Value);
            var prodSelection = new ProducSelectionService(_context);

            var rem = prodSelection.DelProductFromBundle(recomendeBundle, card, customer, survey);

            _output.WriteLine($"After Remove Bundle: {rem?.BundleName}");
            foreach (var productBundle in rem?.ProductIncluded)
            {
                _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}");
            }

            var res = prodSelection.AddProductToBundle(rem, card, customer, survey);

            _output.WriteLine($"Resulting Bundle: {res?.BundleName}");
            foreach (var productBundle in res?.ProductIncluded)
            {
                _output.WriteLine($"\tIncluded Product: {productBundle.Product.ProductName}");
            }

            Assert.Contains(card, res.ProductIncluded.Select(p => p.Product));
        }
예제 #16
0
        public JsonResult Save(CustomerLoyalityViewModel model)
        {
            Response response;
            var      currentUser = GetAuthenticatedUser();
            var      date        = DateUtility.GetDateTime(model.persianDate);
            var      returnDate  = DateUtility.GetDateTime(model.persianReturnDate);

            if (date > DateTime.Now)
            {
                response = new Response()
                {
                    status  = 500,
                    message = "تاریخ انتخاب شده بزرگتر از تاریخ امروز می باشد.",
                };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var personel = db.Person.Where(x => x.MobileNumber == model.phoneNumber).Count();
                    if (personel > 0)
                    {
                        response = new Response()
                        {
                            status  = 500,
                            message = "این شماره متعلق به پرسنل کیا گالری میباشد که شامل مشتریان وفادار نمیشوند.",
                        };
                        return(Json(response, JsonRequestBehavior.AllowGet));
                    }
                }
                if (!ValidateMobileNumber(model.phoneNumber))
                {
                    response = new Response()
                    {
                        status  = 500,
                        message = "تلفن همراه وارد شده صحیح نیست. لطفا تلفن همراه را در قالب 09123456789 وارد نمایید. \n مثال:0912123456789",
                    };
                    return(Json(response, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    using (var db = new KiaGalleryContext())
                    {
                        var SilverCardValue   = db.Settings.SingleOrDefault(x => x.Key == Settings.KeySilverCardValue)?.Value;
                        var GoldenCardValue   = db.Settings.SingleOrDefault(x => x.Key == Settings.KeyGoldenCardValue)?.Value;
                        var PlatinumCardValue = db.Settings.SingleOrDefault(x => x.Key == Settings.KeyPlatinumCardValue)?.Value;

                        var SilverCardLevel   = db.Settings.SingleOrDefault(x => x.Key == Settings.KeySilverCardLevel)?.Value;
                        var GoldenCardLevel   = db.Settings.SingleOrDefault(x => x.Key == Settings.KeyGoldenCardLevel)?.Value;
                        var PlatinumCardLevel = db.Settings.SingleOrDefault(x => x.Key == Settings.KeyPlatinumCardLevel)?.Value;
                        if (model.customerId > 0)
                        {
                            var entity = db.CustomerLoyality.Single(x => x.Id == model.customerId);
                            entity.FirstName   = model.firstName;
                            entity.LastName    = model.lastName;
                            entity.PhoneNumber = model.phoneNumber;
                            db.SaveChanges();
                            response = new Response()
                            {
                                status  = 200,
                                message = "ویرایش اطلاعات با موفقیت انجام شد."
                            };
                            return(Json(response, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            if (model.id > 0)
                            {
                                if (model.purchaseType == PurchaseType.Return)
                                {
                                    var entity = db.CustomerFactor.Single(x => x.Id == model.id);
                                    entity.ReturnDate   = returnDate;
                                    entity.ProductCode  = model.productCode;
                                    entity.FactorNumber = model.factorNumber;
                                    entity.FactorPrice  = model.factorPrice;
                                    entity.PurchaseType = model.purchaseType;
                                    entity.Ip           = Request.UserHostAddress;
                                    entity.ModifyUserId = currentUser.Id;
                                    entity.ModifyDate   = DateTime.Now;
                                    entity.CustomerLoyality.FirstName   = model.firstName;
                                    entity.CustomerLoyality.LastName    = model.lastName;
                                    entity.CustomerLoyality.PhoneNumber = model.phoneNumber;
                                    db.SaveChanges();
                                    response = new Response()
                                    {
                                        status  = 200,
                                        message = "ویرایش اطلاعات با موفقیت انجام شد."
                                    };
                                }
                                else
                                {
                                    var entity = db.CustomerFactor.Single(x => x.Id == model.id);
                                    entity.Date         = date.Value;
                                    entity.ProductCode  = model.productCode;
                                    entity.FactorNumber = model.factorNumber;
                                    entity.FactorPrice  = model.factorPrice;
                                    entity.FactorWeight = model.factorWeight;
                                    entity.PurchaseType = model.purchaseType;
                                    entity.Ip           = Request.UserHostAddress;
                                    entity.ModifyUserId = currentUser.Id;
                                    entity.ModifyDate   = DateTime.Now;
                                    entity.CustomerLoyality.FirstName   = model.firstName;
                                    entity.CustomerLoyality.LastName    = model.lastName;
                                    entity.CustomerLoyality.PhoneNumber = model.phoneNumber;
                                    db.SaveChanges();
                                    response = new Response()
                                    {
                                        status  = 200,
                                        message = "ویرایش اطلاعات با موفقیت انجام شد."
                                    };
                                }
                            }
                            else
                            {
                                var entity = db.CustomerLoyality.SingleOrDefault(x => x.PhoneNumber == model.phoneNumber);
                                //double setting = 1;
                                if (entity != null)
                                {
                                    if (model.purchaseType == PurchaseType.Return)
                                    {
                                        var factorInfo  = db.CustomerFactor.Single(x => x.Id == model.hiddenId && x.CustomerLoyality.PhoneNumber == model.phoneNumber);
                                        var productCode = db.CustomerFactor.Single(x => x.Id == model.hiddenId).ProductCode.Split('-');
                                        var codes       = model.productCode.Split('-');
                                        foreach (var code in codes)
                                        {
                                            if (productCode.Count(v => v == code) > 0)
                                            {
                                                productCode = productCode.Where(x => x != code).ToArray();
                                            }
                                            else
                                            {
                                                response = new Response()
                                                {
                                                    status  = 404,
                                                    message = "کد کالا یافت نشد یامحصولی با این کد قبلا مرجوع شده."
                                                };
                                                return(Json(response, JsonRequestBehavior.AllowGet));
                                            }
                                            if (productCode.Count(v => v == code) == 0)
                                            {
                                                productCode = productCode.Where(x => x != code).ToArray();
                                            }
                                            else
                                            {
                                                response = new Response()
                                                {
                                                    status  = 404,
                                                    message = "کدکالا وارد نشده است."
                                                };
                                                return(Json(response, JsonRequestBehavior.AllowGet));
                                            }
                                        }
                                        string dash = "-";
                                        string stringProductCode;
                                        stringProductCode = string.Join(dash, productCode);
                                        var returnFactor = new CustomerFactor()
                                        {
                                            Date               = factorInfo.Date,
                                            ReturnDate         = returnDate,
                                            ProductCode        = model.productCode,
                                            BranchId           = currentUser.BranchId.Value,
                                            CustomerLoyalityId = entity.Id,
                                            FactorNumber       = model.factorNumber,
                                            FactorPrice        = model.factorPrice,
                                            PurchaseType       = model.purchaseType,
                                            CreateUserId       = currentUser.Id,
                                            ModifyUserId       = currentUser.Id,
                                            CreateDate         = DateTime.Now,
                                            ModifyDate         = DateTime.Now,
                                            Ip = Request.UserHostAddress
                                        };
                                        db.CustomerFactor.Add(returnFactor);
                                        factorInfo.CustomerLoyality.FirstName = model.firstName;
                                        factorInfo.CustomerLoyality.LastName  = model.lastName;
                                        factorInfo.ProductCode  = stringProductCode;
                                        factorInfo.FactorNumber = model.factorNumber;
                                        factorInfo.FactorPrice  = factorInfo.FactorPrice;
                                        factorInfo.PurchaseType = PurchaseType.Buy;
                                        factorInfo.Ip           = Request.UserHostAddress;
                                        factorInfo.ModifyUserId = currentUser.Id;
                                        factorInfo.ModifyDate   = DateTime.Now;
                                        factorInfo.CustomerLoyality.PhoneNumber = model.phoneNumber;
                                        response = new Response()
                                        {
                                            status  = 200,
                                            message = "ثبت اطلاعات با موفقیت انجام شد."
                                        };
                                        db.SaveChanges();
                                    }
                                    else
                                    {
                                        var factor = new CustomerFactor()
                                        {
                                            Date               = date.Value,
                                            ProductCode        = model.productCode,
                                            BranchId           = currentUser.BranchId.Value,
                                            CustomerLoyalityId = entity.Id,
                                            FactorNumber       = model.factorNumber,
                                            FactorPrice        = model.factorPrice,
                                            FactorWeight       = model.factorWeight,
                                            PurchaseType       = model.purchaseType,
                                            CreateUserId       = currentUser.Id,
                                            ModifyUserId       = currentUser.Id,
                                            CreateDate         = DateTime.Now,
                                            ModifyDate         = DateTime.Now,
                                            Ip = Request.UserHostAddress,
                                        };
                                        //entity.Credit = long.Parse(Math.Round((model.factorPrice * setting / 100) / 1000).ToString());
                                        Random random = new Random(Guid.NewGuid().GetHashCode());
                                        int    number = random.Next(10000, 99999);
                                        var    survey = new CustomerSurvey()
                                        {
                                            Code           = number.ToString(),
                                            CustomerFactor = factor,
                                            CreateDate     = DateTime.Now,
                                            CreateUserId   = currentUser.Id,
                                            Ip             = Request.UserHostAddress
                                        };
                                        //Task.Factory.StartNew(() =>
                                        //{
                                        //NikSmsWebServiceClient.SendSmsNik("srvey.kia-gallery.com/" + number.ToString(), "09354047788");
                                        //    NikSmsWebServiceClient.SendSmsNik("survey.kia-gallery.com/"+ number.ToString(), "09193121247");
                                        //    NikSmsWebServiceClient.SendSmsNik("www.kia-gallery.com/" + number.ToString(), model.phoneNumber);
                                        //});
                                        db.CustomerSurvey.Add(survey);
                                        response = new Response()
                                        {
                                            status  = 200,
                                            message = "ثبت اطلاعات با موفقیت انجام شد."
                                        };
                                        db.CustomerFactor.Add(factor);
                                        db.SaveChanges();
                                    }
                                }
                                else
                                {
                                    //if (entity.CustomerCardLevel == CustomerCardLevel.Silver)
                                    //{
                                    //    setting = double.Parse(SilverCardValue);
                                    //}
                                    //if (entity.CustomerCardLevel == CustomerCardLevel.Gold)
                                    //{
                                    //    setting = double.Parse(GoldenCardValue);
                                    //}
                                    //if (entity.CustomerCardLevel == CustomerCardLevel.Platinum)
                                    //{
                                    //    setting = double.Parse(PlatinumCardValue);
                                    //}

                                    var loyality = new CustomerLoyality()
                                    {
                                        FirstName = model.firstName,
                                        LastName  = model.lastName,
                                        //Credit = long.Parse(Math.Round((model.factorPrice * setting / 100) / 1000).ToString()),
                                        PhoneNumber  = model.phoneNumber,
                                        Date         = DateTime.Now,
                                        CreateUserId = currentUser.Id,
                                        ModifyUserId = currentUser.Id,
                                        CreateDate   = DateTime.Now,
                                        ModifyDate   = DateTime.Now,
                                        Ip           = Request.UserHostAddress,
                                    };
                                    var factor = new CustomerFactor()
                                    {
                                        Date             = date.Value,
                                        ProductCode      = model.productCode,
                                        ReturnDate       = returnDate,
                                        BranchId         = currentUser.BranchId.Value,
                                        CustomerLoyality = loyality,
                                        FactorNumber     = model.factorNumber,
                                        FactorPrice      = model.factorPrice,
                                        FactorWeight     = model.factorWeight,
                                        PurchaseType     = model.purchaseType,
                                        CreateUserId     = currentUser.Id,
                                        ModifyUserId     = currentUser.Id,
                                        CreateDate       = DateTime.Now,
                                        ModifyDate       = DateTime.Now,
                                        Ip = Request.UserHostAddress
                                    };

                                    Random random = new Random(Guid.NewGuid().GetHashCode());
                                    int    number = random.Next(10000, 99999);
                                    var    survey = new CustomerSurvey()
                                    {
                                        Code           = number.ToString(),
                                        CustomerFactor = factor,
                                        CreateDate     = DateTime.Now,
                                        CreateUserId   = currentUser.Id,
                                        Ip             = Request.UserHostAddress
                                    };
                                    //Task.Factory.StartNew(() =>
                                    //{
                                    //    NikSmsWebServiceClient.SendSmsNik("srvey.kia-gallery.com/" + number.ToString(), "09354047788");
                                    //    NikSmsWebServiceClient.SendSmsNik("survey.kia-gallery.com/" + number.ToString(), "09193121247");
                                    //});
                                    db.CustomerSurvey.Add(survey);
                                    response = new Response()
                                    {
                                        status  = 200,
                                        message = "ثبت اطلاعات با موفقیت انجام شد."
                                    };
                                    db.CustomerLoyality.Add(loyality);

                                    db.CustomerFactor.Add(factor);
                                    db.SaveChanges();

                                    //if (loyality.Credit >= long.Parse(SilverCardLevel))
                                    //{
                                    //    var customerCardlevelLog = new CustomerCreditLog()
                                    //    {
                                    //        CustomerId = loyality.Id,
                                    //        Credit = long.Parse(Math.Round((model.factorPrice * setting / 100) / 1000).ToString()),
                                    //        CustomerCardLevel = CustomerCardLevel.Silver
                                    //    };
                                    //}
                                    //else if (loyality.Credit >= long.Parse(GoldenCardLevel))
                                    //{
                                    //    var customerCardlevelLog = new CustomerCreditLog()
                                    //    {
                                    //        CustomerId = loyality.Id,
                                    //        Credit = long.Parse(Math.Round((model.factorPrice * setting / 100) / 1000).ToString()),
                                    //        CustomerCardLevel = CustomerCardLevel.Gold
                                    //    };
                                    //}
                                    //else if (loyality.Credit >= long.Parse(PlatinumCardLevel))
                                    //{
                                    //    var customerCardlevelLog = new CustomerCreditLog()
                                    //    {
                                    //        CustomerId = loyality.Id,
                                    //        Credit = long.Parse(Math.Round((model.factorPrice * setting / 100) / 1000).ToString()),
                                    //        CustomerCardLevel = CustomerCardLevel.Platinum
                                    //    };
                                    //}
                                    //else
                                    //{
                                    //    var customerCardlevelLog = new CustomerCreditLog()
                                    //    {
                                    //        CustomerId = loyality.Id,
                                    //        Credit = long.Parse(Math.Round((model.factorPrice * setting / 100) / 1000).ToString()),
                                    //        CustomerCardLevel = CustomerCardLevel.None
                                    //    };
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Submit(int id = 0, int number = 0)
        {
            //That ensures that parameters passed are correct
            CustomerSurvey survey = db.CustomerSurveys.Find(id);

            if (survey == null)
            {
                return(HttpNotFound());
            }

            CustomerAnswer answer = survey.CustomerAnswers.SingleOrDefault(a => a.questionId == number);

            if (answer == null)
            {
                /*if answer does not exist --> check if question is part of base survey
                 * (ensures that parameters passed are correct)*/
                bool includedInBaseSurvey = survey.GenericSurvey.Questions.Any(q => q.questionId == number);
                if (!includedInBaseSurvey)
                {
                    return(HttpNotFound());
                }
                //If question is included --> create new Dummy customer Answer
                else
                {
                    answer = new CustomerAnswer()
                    {
                        surveyId = id, questionId = number, answerText = "-", observerStatusValue = 0
                    };
                    db.CustomerAnswers.Add(answer);
                    db.SaveChanges();
                }
            }

            #region Additional info
            //Question type into account (1: long, 2: short;)
            ViewBag.QuestionType = answer.Question.questionTypeId;
            //Drop downs
            ViewBag.answerOptionNumber =
                new SelectList(answer.Question.AnswerOptions, "answerNumber", "answerText", answer.answerOptionNumber);
            ViewBag.observerStatusValue =
                new SelectList(db.ObserverStatus, "statusValue", "description", answer.observerStatusValue);

            int measuresAmount = answer.Question.GenericCountermeasures.Count;
            ViewBag.MeasuresAmount = measuresAmount > 3 ? 3 : measuresAmount;

            ViewBag.countermeasureId1 =
                new SelectList(answer.Question.GenericCountermeasures, "countermeasureId", "title", answer.countermeasureId1);
            ViewBag.countermeasureId2 =
                new SelectList(answer.Question.GenericCountermeasures, "countermeasureId", "title", answer.countermeasureId2);
            ViewBag.countermeasureId3 =
                new SelectList(answer.Question.GenericCountermeasures, "countermeasureId", "title", answer.countermeasureId3);

            #endregion

            if (Request.IsAjaxRequest())
            {
                return(PartialView(answer));
            }

            return(View(answer));
        }
        public ActionResult Index(int id = 0)
        {
            CustomerSurvey customerSurvey = db.CustomerSurveys.Find(id);

            if (customerSurvey == null)
            {
                return(HttpNotFound());
            }

            //Only participating users can see/modify Report
            string currentUser = User.Identity.Name;

            if (currentUser != customerSurvey.UserAccount.userName && currentUser != customerSurvey.UserAccount1.userName)
            {
                TempData["Message"] = "Oops! Only survey observer and supervisor can access the survey report";
                return(RedirectToAction("Index", "CustomerSurvey"));
            }

            //Teacher see only created by student answers
            List <CustomerAnswer> answerList   = customerSurvey.CustomerAnswers.ToList();
            List <Question>       questionList = customerSurvey.GenericSurvey.Questions.ToList();

            ViewBag.SurveyTitle = customerSurvey.customerSurveyTitle;

            //Additional Info to Display
            #region SidebarInfo

            int questionsAmount    = questionList.Count;
            int questionsAnswered  = answerList.Where(a => a.answerStatusValue > (int)AnswerStatus.NotSet).Count();
            int questionsValidated = answerList.Where(a => a.answerStatusValue == (int)AnswerStatus.Validated).Count();
            ViewBag.AnsweredQuestions  = String.Format("{0} / {1}", questionsAnswered, questionsAmount);
            ViewBag.ValidatedQuestions = String.Format("{0} / {1}", questionsValidated, questionsAmount);

            double avgObserverStatus = (answerList.Average(x => x.observerStatusValue)) ?? 0;
            ViewBag.AverageObserverStatus = Math.Round(avgObserverStatus, 2);

            /* Factor here derrives from AnswerStatusValue Range.
             * Minima = 0, Maxima = 4 --> Four answers with value 4 should give 100 %
             * --> 16/4 * factor = 100 % --> factor = 25 */
            int    factor             = 25;
            double averageAnswerValue = (answerList.Average(z => z.answerStatusValue)) ?? 0;
            int    surveyProgress     = (int)Math.Round(averageAnswerValue * factor);
            ViewBag.SurveyProgress = String.Format("{0}%", surveyProgress);

            #endregion

            if (User.IsInRole("Teacher"))
            {
                return(View("IndexTeacher", answerList));
            }
            else
            {
                ViewBag.surveyId = customerSurvey.surveyId;

                if (TempData["SubmitStatus"] != null && TempData["SubmitStatus"] == "1")
                {
                    ViewBag.Warning = "Answer is saved";
                }
                else if (TempData["SubmitStatus"] != null && TempData["SubmitStatus"] == "0")
                {
                    ViewBag.Error = "Wrong input";
                }


                return(View("IndexStudent", questionList));
            }
        }
예제 #19
0
 public TaxInformationResponse Process(CustomerSurvey customerSurvey)
 {
     return(new TaxInformationResponse {
         TaxRate = _defaultTaxRate
     });
 }