public IHttpActionResult Register([FromBody] Users user)
        {
            System.Web.Http.Results.StatusCodeResult status;
            using (IUMdbEntities entities = new IUMdbEntities())
            {
                #region Validation

                #region checkIfUserIsNull
                if (user == null)
                {
                    status = new System.Web.Http.Results.StatusCodeResult(HttpStatusCode.Conflict, this);
                    return(status);
                }
                #endregion

                #region checkIfUsernameIsTaken
                bool checkIfUsernameIsTaken = entities.Users
                                              .Any(e => e.Username == user.Username);

                if (checkIfUsernameIsTaken)
                {
                    status = new System.Web.Http.Results.StatusCodeResult(HttpStatusCode.Conflict, this);
                    return(status);
                }
                #endregion

                #endregion

                CryptoService cryptoService  = new CryptoService();
                string        hashedPassword = cryptoService.GetHashedString(user.Password);

                Users newUser = new Users()
                {
                    Username = user.Username,
                    Password = hashedPassword,
                    GoogleId = user.GoogleId
                };
                entities.Users.Add(newUser);
                entities.SaveChanges();

                Users dbUser = entities.Users
                               .Where(e => e.Username == user.Username)
                               .First();

                UserRoles employeeRole = entities.UserRoles
                                         .Where(e => e.RoleName == "Employee")
                                         .First();

                Workplaces newWorkplace = new Workplaces()
                {
                    UserId     = dbUser.Id,
                    UserRoleId = employeeRole.Id
                };
                entities.Workplaces.Add(newWorkplace);
                entities.SaveChanges();

                status = new System.Web.Http.Results.StatusCodeResult(HttpStatusCode.Created, this);
                return(status);
            }
        }
Пример #2
0
 public void Clear()
 {
     lock (Dwellers) Dwellers.Clear();
     Homes.Clear();
     Cafes.Clear();
     Workplaces.Clear();
 }
Пример #3
0
        public Workplace(DateTime dateOfEmployment, string department, Workplaces emplWorkplace, float yearSalary, int phoneNumber, int roomNumber)
        {
            DateOfEmployment = dateOfEmployment;
            EmplWorkplace    = emplWorkplace;
            Department       = department;
            YearSalary       = yearSalary;

            if (emplWorkplace.Equals(Workplaces.Asystent))
            {
                PhoneNumber = phoneNumber;
            }
            else
            {
                PhoneNumber = 0;
            }

            if (emplWorkplace.Equals(Workplaces.Dyrektor))
            {
                RoomNumber = roomNumber;
            }
            else
            {
                RoomNumber = 0;
            }
        }
Пример #4
0
        public SmallEditor()
        {
            InitializeComponent();

            DBBodyTypes     = new BodyTypes();
            DBClasses       = new Classes();
            DBColors        = new Colors();
            DBGearTypes     = new GearTypes();
            DBLanguages     = new Languages();
            DBManafacturers = new Manafacturers();
            DBWorkplaces    = new Workplaces();
        }
Пример #5
0
        public void FilterCollection(string filteringSubstring)
        {
            filteringSubstring = filteringSubstring.Trim().ToLower();

            if (string.IsNullOrEmpty(filteringSubstring))
            {
                FilteredWorkplaces.Clear();
                return;
            }

            FilteredWorkplaces = Workplaces.Where(x => x.Title.ToLower().Contains(filteringSubstring)).ToList();
        }
Пример #6
0
        //private void CheckNewLocation(IDweller dweller, IBuilding obj)
        //{
        //	if (dweller.Position.Value == obj.Position.Value)
        //	{
        //		// yep
        //		dweller.EnterBuilding(obj);
        //	}
        //}

        public void Add(IBuilding building)
        {
            switch (building)
            {
            case IHome home:
                Homes.Add(home);
                break;

            case IWorkplace workplace:
                Workplaces.Add(workplace);
                break;

            case ICafe cafe:
                Cafes.Add(cafe);
                break;
            }
        }
Пример #7
0
        public ElementControlService()
        {
            DBAutomobilesData = new AutomobilesData();
            DBClients         = new Clients();
            DBOffices         = new Offices();
            DBSelledCars      = new SelledCars();
            DBWorkers         = new Workers();

            DBBodyTypes     = new BodyTypes();
            DBClasses       = new Classes();
            DBColors        = new Colors();
            DBCountries     = new Countries();
            DBGearTypes     = new GearTypes();
            DBLanguages     = new Languages();
            DBManafacturers = new Manafacturers();
            DBWorkplaces    = new Workplaces();
        }
Пример #8
0
        public MainForm()
        {
            InitializeComponent();

            // ConnectionWizard ConWiz = new ConnectionWizard();
            // ConWiz.StartPosition = FormStartPosition.CenterScreen;
            // ConWiz.ShowDialog();
            PageID = DatabaseControlService.LastPage;

            About = new AboutForm();

            //Editor Forms
            DBAutomobileEditor  = new AutomobilesEditor();
            DBClientEditor      = new ClientsEditor();
            DBOfficeEditor      = new OfficesEditor();
            DBOrderEditor       = new OrdersEditor();
            DBPresenceCarEditor = new PresenceCarsEditor();
            DBSellEditor        = new SellsEditor();
            DBWorkerEditor      = new WorkersEditor();

            //Tables
            DBAutomobilesData = new AutomobilesData();
            DBBodyTypes       = new BodyTypes();
            DBClients         = new Clients();
            DBColors          = new Colors();
            DBCountries       = new Countries();
            DBLanguages       = new Languages();
            DBManafacturers   = new Manafacturers();
            DBOffices         = new Offices();
            DBOrders          = new Orders();
            DBPresenceCars    = new PresenceCars();
            DBSelledCars      = new SelledCars();
            DBSells           = new Sells();
            DBWorkers         = new Workers();
            DBWorkplaces      = new Workplaces();

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.MultiSelect   = false;

            buttonInsert.Enabled = false;
            buttonUpdate.Enabled = false;
            buttonDelete.Enabled = false;

            ShowDialog();
        }
Пример #9
0
        public SmallSelector()
        {
            InitializeComponent();

            DBBodyTypes     = new BodyTypes();
            DBClasses       = new Classes();
            DBColors        = new Colors();
            DBCountries     = new Countries();
            DBGearTypes     = new GearTypes();
            DBLanguages     = new Languages();
            DBManafacturers = new Manafacturers();
            DBWorkplaces    = new Workplaces();

            DBSmallEditor   = new SmallEditor();
            DBCountryEditor = new CountriesEditor();

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.MultiSelect   = false;
        }
Пример #10
0
        public async Task DeleteWorkplace(object wp)
        {
            try
            {
                var workplace = wp as Workplace;

                if (workplace == null)
                {
                    return;
                }

                IsBusy = true;
                await _workplacesManager.DeleteWorkplace(workplace.Id);

                Workplaces.Remove(workplace);
                IsBusy = false;
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }
Пример #11
0
 public Workplaces GetWorkplaces()
 {
     workplaces = new Workplaces(workplacesTrans);
     return(workplaces);
 }