Esempio n. 1
0
        private static void UpgradeStandardToPremium()
        {
            var standard = new StandardUser
            {
                ID        = 1,
                FirstName = "Standard",
                LastName  = "Standerson",
                UserName  = "******",
                Password  = "******"
            };

            var premium = new PremiumUser(standard);

            var result = (premium is PremiumUser);

            Console.WriteLine(result);
        }
        static void Main(string[] args)
        {
            //Customer generic example
            Customer <string> simpleCustomer = new Customer <string>
            {
                FirstName = "Ivan",
                LastName  = "Ivanov",
                Address   = "9th Kingdom, SillyWilly str, 13"
            };

            Customer <Address> customer = new Customer <Address>
            {
                FirstName = "Friedrich",
                LastName  = "Nietzsche",
                Address   = new Address
                {
                    CityName    = "Röcken",
                    StreetName  = "Gostauer Weg",
                    HouseNumber = 2
                }
            };

            //Customer abstraction example
            //Например, если выбрана лиценция обычного пользователя открывается форма c полями для CommonUser
            CommonUser commonUser = new CommonUser
            {
                FirstName        = "John",
                LastName         = "Anderson",
                CreditCardNumber = "1234123412341234",
                ITN = 123526729406
            };

            //Если при регистрации выбрана опция премиум пользователя, открывается форма с полями для PermiumUser
            PremiumUser premiumUser = new PremiumUser
            {
                FirstName        = "John",
                LastName         = "Anderson",
                PremiumCarNumber = 1
            };

            List <IUser> users = new List <IUser>();

            users.Add(commonUser);
            users.Add(premiumUser);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ChatMediator mediator = new ChatMediator();
            IUser        a        = new BasicUser("A", mediator);
            IUser        b        = new BasicUser("B", mediator);
            IUser        c        = new PremiumUser("C", mediator);
            IUser        d        = new PremiumUser("D", mediator);

            //adding to list of receiver
            mediator.AddUser(a);
            mediator.AddUser(b);
            mediator.AddUser(c);
            mediator.AddUser(d);
            //sending message
            a.SendMessage("Hi");

            Console.ReadLine();
        }
Esempio n. 4
0
    IEnumerator GetData()
    {
        using (WWW www = new WWW(path))
        {
            yield return(www);

            //If there is no error
            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log("There is an error");
            }


            var jsonText = www.text;
            user        = JsonUtility.FromJson <User>(jsonText);
            premiumUser = JsonUtility.FromJson <PremiumUser>(jsonText);
        }
    }
Esempio n. 5
0
        private static void AddExample()
        {
            using var context = new MASContext();
            User person = new PremiumUser()
            {
                PasswordHash = "secret",
                Name         = "Michal",
                CreatedAt    = DateTime.Today,
                Email        = "*****@*****.**"
            };

            var city = new City
            {
                Name = "Piaseczno"
            };

            city.User.Add(person);

            context.City.Add(city);
            context.SaveChanges();
        }
        /// <summary>
        /// Runners this instance.
        /// </summary>
        public void Runner()
        {
            ////creating object of chat mediator class using reference of inerface
            IChatMediator chatMediator = new ChatMediator();
            ////creating object of basic user class with abstract class reference
            User manjunath = new BasicUser(chatMediator, "Manjunath");
            ////creating object of Premium user class with abstract class reference
            User karan = new PremiumUser(chatMediator, "Karan");
            ////creating object of basic premium class with abstract class reference
            User parmesh = new PremiumUser(chatMediator, "Parmesh");

            ////calling add user method with the reference of interface
            chatMediator.AddUser(manjunath);
            ////calling add user method with the reference of interface
            chatMediator.AddUser(karan);
            ////calling add user method with the reference of interface
            chatMediator.AddUser(parmesh);
            ////creating object of basic user class with abstract class reference
            User salu = new BasicUser(chatMediator, "Salu");

            ////calling add user method with the reference of interface
            chatMediator.AddUser(salu);
            salu.SendMessage("salu:->Hey i am online");
        }
        public ActionResult Create(RegisterUser account)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    User reg;

                    if (account.uPremiumUser)
                    {
                        reg = new PremiumUser();
                    }
                    else
                    {
                        reg = new BasicUser();
                    }

                    reg.Username = account.uName;
                    DateTime oDate = Convert.ToDateTime(account.uDOB);
                    reg.Birthdate = oDate;
                    reg.Password  = Helpers.SHA.Encode(account.uPwd);

                    bool result      = checkUserExists(account.uName);
                    bool resultemail = checkMailExists(account.uEmail);
                    if (result == true)
                    {
                        ModelState.AddModelError("", account.uName + " already taken.");
                    }
                    else
                    if (resultemail == true)
                    {
                        ModelState.AddModelError("", account.uEmail + " already taken.");
                    }
                    else
                    if (result == false && resultemail == false)
                    {
                        reg.Email       = account.uEmail;
                        reg.Premiumuser = account.uPremiumUser;


                        if (account.uPremiumUser)
                        {
                            reg.Role = "PremiumUser";
                            userGateway.Insert(reg);
                        }
                        else
                        {
                            reg.Role = "BasicUser";
                            userGateway.Insert(reg);
                        }

                        ModelState.AddModelError("", account.uName + " successfully registered.");
                    }
                }
                catch (Exception e)
                {
                    ViewBag.Message = e.ToString();
                }
            }
            return(View("RegisterPage"));
        }
 public IResult UpdatePremiumUser(PremiumUser premiumUser)
 {
     _premiumUserDal.Update(premiumUser);
     return(new SuccessResult());
 }
 public IDataResult <List <OperationClaim> > GetClaims(PremiumUser premiumUser)
 {
     return(new SuccessDataResult <List <OperationClaim> >(_premiumUserDal.GetClaims(premiumUser)));
 }
Esempio n. 10
0
 public IResult AddPremiumUser(PremiumUser premiumUser)
 {
     _premiumUserDal.Add(premiumUser);
     return(new SuccessResult());
 }
        static void Main(string[] args)
        {
            Seed();

            while (true)
            {
                //login/register
                if (_currentUser == null)
                {
                    int loginChoice = _uiService.LogInMenu();

                    //login
                    if (loginChoice == 1)
                    {
                        int      roleChoice = _uiService.RoleMenu();
                        UserRole role       = (UserRole)roleChoice;
                        Console.Clear();

                        Console.WriteLine("Enter Username:"******"Enter Password:"******"Enter First Name:");
                        newUser.FirstName = Console.ReadLine();
                        Console.WriteLine("Enter Last Name:");
                        newUser.LastName = Console.ReadLine();
                        Console.WriteLine("Enter Username:"******"Enter Password:"******"Train":

                    //int trainChoice;

                    //if (_currentUser.Role == UserRole.Premium)
                    //{
                    //    trainChoice = _uiService.TrainMenu();
                    //}
                    //else
                    //{
                    //    trainChoice = 1;
                    //}

                    int trainChoice = _currentUser.Role == UserRole.Premium ? _uiService.TrainMenu() : 1;

                    //video training
                    if (trainChoice == 1)
                    {
                        int           trainingItem = _uiService.TrainMenuItems(_videoTrainingService.GetTrainings());
                        VideoTraining training     = _videoTrainingService.GetTrainingByIndex(trainingItem - 1);
                        Console.WriteLine(training.Title);
                        Console.WriteLine($"Link: {training.Link}");
                        Console.WriteLine($"Raiting: {training.Rating}");
                        Console.WriteLine($"Time: {training.Time} minutes");
                        Console.ReadLine();
                    }

                    //live training
                    if (trainChoice == 2)
                    {
                        int          trainingItem = _uiService.TrainMenuItems(_liveTrainingService.GetTrainings());
                        LiveTraining training     = _liveTrainingService.GetTrainingByIndex(trainingItem - 1);
                        Console.WriteLine(training.Title);
                        Console.WriteLine($"The training starts at: {training.NextSession}");
                        Console.WriteLine($"Raiting: {training.Rating}");
                        Console.WriteLine($"Time: {training.Time} minutes");
                        Console.ReadLine();
                    }

                    break;

                case "Upgrade to premium":

                    //suggestion for implementing real UpgradeToPremium functionality

                    // logout
                    // keep the currently logged user in a variable
                    // find and delete that user from standardUserService
                    // regsiter new premium user in the premiumUserService with the same data
                    // log in the newly registered user

                    Console.Clear();
                    Console.WriteLine("Do you really want to upgrade to premium? It will cost you 15$.");
                    Console.WriteLine("Press enter to upgrade!");

                    Console.ReadLine();

                    User tempCurrentUser = _currentUser;
                    _currentUser = null;
                    _standardUserService.DeleteById(tempCurrentUser.Id);
                    PremiumUser newUser = _premiumUserService.MapToPremiumUser(tempCurrentUser);
                    User        user    = _premiumUserService.Register(newUser);
                    _currentUser = user;

                    Console.WriteLine("Createing new premium sibscription, please wait ....");
                    Thread.Sleep(2000);

                    Console.WriteLine($"You have succesfully buy a premium subscription. Welcome back {_currentUser.Username}.");
                    Thread.Sleep(2000);

                    Console.ReadLine();
                    break;

                case "Reschedule training":
                    List <LiveTraining> trainings = _liveTrainingService.GetTrainings().Where(training => training.Trainer.Id == _currentUser.Id).ToList();
                    if (trainings.Count == 0)
                    {
                        Console.WriteLine("No available trainings.");
                        Console.ReadLine();
                    }
                    else
                    {
                        int trainingChoice = _uiService.ChooseEntitiesMenu(trainings);
                        Console.WriteLine("How many days fo you want to reschedule the training: ");
                        int days = ValidationHelper.ValidateNumber(Console.ReadLine(), 10);
                        _trainerUserService.GetById(_currentUser.Id).ChangeSchedule(trainings[trainingChoice - 1], days);
                        Console.WriteLine("Schadule changed!");
                        Console.ReadLine();
                    }
                    break;

                case "Account":
                    int accountChoice = _uiService.AccountMenu();
                    Console.Clear();
                    if (accountChoice == 1)
                    {
                        //Change Info
                        Console.WriteLine("Enter First Name:");
                        string firstName = Console.ReadLine();
                        Console.WriteLine("Enter Last Name:");
                        string lastName = Console.ReadLine();

                        switch (_currentUser.Role)
                        {
                        case UserRole.Standard:
                            _standardUserService.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;

                        case UserRole.Premium:
                            _premiumUserService.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;

                        case UserRole.Trainer:
                            _trainerUserService.ChangeInfo(_currentUser.Id, firstName, lastName);
                            break;

                        default:
                            break;
                        }
                    }
                    else if (accountChoice == 2)
                    {
                        //Check Subscription
                        Console.WriteLine($"Your subscription is {_currentUser.Role}");
                        Console.ReadLine();
                    }
                    else if (accountChoice == 3)
                    {
                        //Change Password
                        Console.WriteLine("Enter Old Password:"******"Enter New Password:"******"Log Out":
                    _currentUser = null;
                    break;

                default:
                    break;
                }
            }
        }