public IHttpActionResult Register(bool official, CustomerCardRegistrationModel registrationData)
        {
            // check if the user has already registered for participation and redirect him to the correct action
            var participantFound = this.Data.Customers.Any(registrationData.ContestId, this.UserProfile.Id, official);

            if (participantFound)
            {
                return this.Get(registrationData.ContestId, official);
            }

            var contest = this.Data.CustomerCards.GetById(registrationData.ContestId);
            ValidateContest(contest, official);

            if (official && contest.HasCustomerCardPassword)
            {
                if (string.IsNullOrEmpty(registrationData.Password))
                {
                    return this.BadRequest("Password");
                }
                else if (contest.CustomerCardPassword != registrationData.Password)
                {
                    return this.BadRequest("Password");
                }
            }

            var questionsToAnswerCount = official ?
                contest.Questions.Count(x => x.AskOfficialCustomers) :
                contest.Questions.Count(x => x.AskPracticeCustomers);

            if (questionsToAnswerCount != registrationData.Questions.Count())
            {
                return this.BadRequest("Questions");
            }

            var contestQuestions = contest.Questions.ToList();

            var participant = new Customer(registrationData.ContestId, this.UserProfile.Id, official);
            this.Data.Customers.Add(participant);
            var counter = 0;
            foreach (var question in registrationData.Questions)
            {
                var contestQuestion = contestQuestions.FirstOrDefault(x => x.Id == question.QuestionId);

                var regularExpression = contestQuestion.RegularExpressionValidation;
                bool correctlyAnswered = false;

                if (!string.IsNullOrEmpty(regularExpression))
                {
                    correctlyAnswered = Regex.IsMatch(question.Answer, regularExpression);
                }

                participant.Answers.Add(new CustomerAnswer
                {
                    CustomerCardQuestionId = question.QuestionId,
                    Answer = question.Answer
                });

                counter++;
            }

            if (!this.ModelState.IsValid)
            {
                return this.Ok(new CustomerCardRegistrationDataModel(contest, registrationData, official));
            }

            this.Data.SaveChanges();

            return this.Get(registrationData.ContestId, official);
        }
        public IHttpActionResult Register(int id, bool official)
        {
            var participantFound = this.Data.Customers.Any(id, this.UserProfile.Id, official);
            if (participantFound)
            {
                // Participant exists. Redirect to index page.
                return this.Get(id, official);
            }

            var contest = this.Data.CustomerCards.All().Include(x => x.Questions).FirstOrDefault(x => x.Id == id);

            ValidateContest(contest, official);

            if (contest.ShouldShowRegistrationForm(official))
            {
                var contestRegistrationModel = new CustomerCardRegistrationDataModel(contest, official);
                return this.Ok(contestRegistrationModel);
            }

            var customer = new Customer(id, this.UserProfile.Id, official);
            this.Data.Customers.Add(customer);
            this.Data.SaveChanges();

            return this.Get(id, official);
        }
        private static void AddData(TechSupportDbContext context)
        {
            var names = GetCustomerName();

            var customer = new Customer()
            {
                IsOfficial = true,
                CreatedOn = GetDate(),
                IsDeleted = false,
                IsHidden = false
            };
            context.Customers.Add(customer);
            context.SaveChanges();
            var data = new CustomerCard();

            for (int i = 0; i < names.Length; i++)
            {
                data.CustomerFirstName = names[i].Substring(0, names[i].IndexOf(" "));
                data.CustomerLastName = names[i].Substring(names[i].IndexOf(" ") + 1);
                data.CustomerAddress = string.Format("Karlovo{0}", i + 1);
                //data.Description = cc[i];
                data.Price = i + 10;
                data.IsVisible = true;
                //data.CustomerCardPassword = "******";
                data.Informed = false;
                //data.Comment = cc[i];
                //data.EnrollmentDate = DateTime.Now;
                //data.EndDate = DateTime.Now;
                data.Warranty = true;
                data.CustomerId = customer.Id;
                data.CreatedOn = GetDate();
                data.IsHidden = false;
                data.IsDeleted = false;
                context.CustomerCards.Add(data);
                context.SaveChanges();
            }
        }