Beispiel #1
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                int id        = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                var companyId = (Data.Company)comboBox1.SelectedItem;
                using (UnitOfWork db = new UnitOfWork())
                {
                    Data.Food model    = db.FoodService.GetOne(id);
                    EditFood  formEdit = new EditFood();
                    formEdit.foodId        = id;
                    formEdit.CompanyId     = companyId.CompanyId;
                    formEdit.FoodName.Text = model.FoodName;

                    if (formEdit.ShowDialog() == DialogResult.OK)
                    {
                        ShowFoodGrid();
                    }
                }
            }
            else
            {
                RtlMessageBox.Show("آیتمی انتخاب نشده است");
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(FoodName.Text))
            {
                errorProvider1.SetError(FoodName, "لطفا نام را وارد نمایید");
                return;
            }

            var company = (Data.Company)comboBox1.SelectedItem;

            using (UnitOfWork db = new UnitOfWork())
            {
                var model = new Data.Food()
                {
                    FoodName  = FoodName.Text,
                    CompanyId = company.CompanyId,
                    Active    = true,
                };

                if (db.FoodService.InsertFood(model))
                {
                    db.Save();
                    RtlMessageBox.Show("عملیات با موفقیت انجام شد");
                }
                else
                {
                    RtlMessageBox.Show("کالا ثبت نگردید");
                }
            }
        }
Beispiel #3
0
        public UserViewModels GetUserByID(int UserID)
        {
            // Attempt to find the user through the requested username.
            Data.User dUser = _repository.Get <Data.User>(x => x.UserID == UserID);

            // Ensure that we actually found someone through the username.
            if (dUser == null)
            {
                // We did not find anyone by the provided username in the database.
                return(UserNotFound());
            }

            // Get the User's food preference from the database
            Data.Food dataFood = _repository.Get <Data.Food>(x => x.FoodID == dUser.Food_ID);

            // Ensure that we found a valid food preference
            if (dataFood == null)
            {
                // The food wasn't found
                return(null);
            }

            // Combine the foods and user information for the database for the user object
            Container_Classes.User containerUser = Container_Classes.User.DataUserToUser(dUser, dataFood.Food1);

            // Create the model to return the information to the view.
            UserViewModels model = new UserViewModels();

            model.User = containerUser;

            return(model);
        }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(FoodName.Text))
            {
                errorProvider1.SetError(FoodName, "لطفا نام را وارد نمایید");
                return;
            }

            using (UnitOfWork db = new UnitOfWork())
            {
                var model = new Data.Food()
                {
                    Id        = foodId,
                    FoodName  = FoodName.Text,
                    CompanyId = CompanyId,
                    Active    = true,
                };

                if (db.FoodService.UpdateFood(model))
                {
                    db.Save();
                    RtlMessageBox.Show("عملیات با موفقیت انجام شد");
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    RtlMessageBox.Show("کالا ثبت نگردید");
                }
            }
        }
Beispiel #5
0
        private Models.Food _Map(Data.Food source)
        {
            var model = new Models.Food
            {
                ID    = source.ID,
                Food1 = source.Food1
            };

            return(model);
        }
Beispiel #6
0
        // Once the controller has passed the User info and foods list it can be inserted into the database
        // and a view of that inserted user is returned.
        public UserViewModels CreateUser(Container_Classes.User NewUser)
        {
            // Ensure that the User does not already exist in the database.
            if (_repository.Get <Data.User>(x => x.Username == NewUser.Username) != null)
            {
                // The user is in the database, this should be a special error.
                return(null);
            }

            int foodIndex = int.Parse(NewUser.Foods);

            // Find out the food id that the user provided and get the ID number for the database entry.
            Data.Food userFood = _repository.Get <Data.Food>(x => x.FoodID == foodIndex);
            if (userFood == null)
            {
                // Food requested was not in the database!
                return(null);
            }

            // Add the new user to the database.
            Data.User dUser = Container_Classes.User.UserToDataUser(NewUser, userFood.FoodID);
            _repository.Add <Data.User>(dUser);

            _repository.SaveChanges();

            // Get the inserted NewUser back from the database
            dUser = _repository.Get <Data.User>(x => x.Username == NewUser.Username);
            if (dUser == null)
            {
                // The user was not uploaded into the database.
                return(UserNotFound());
            }

            // Create the model to return the information to the view.
            UserViewModels model = new UserViewModels();

            model.User = NewUser;

            return(model);
        }
Beispiel #7
0
        public UserViewModels UpdateUser(Container_Classes.User UpdatedUser)
        {
            //Attempt to find the user from the database before sending update.
            if (_repository.Get <Container_Classes.User>(x => x.Username == UpdatedUser.Username) == null)
            {
                // The user was not found in the database
                return(UserNotFound());
            }

            int foodID = int.Parse(UpdatedUser.Foods);

            // Get the food ID from the database to store in the user object
            Data.Food dataFood = _repository.Get <Data.Food>(x => x.FoodID == foodID);
            if (dataFood == null)
            {
                // The food ID wasn't found
                return(null);
            }

            Data.User dUser = Container_Classes.User.UserToDataUser(UpdatedUser, dataFood.FoodID);
            _repository.Update <Data.User>(dUser);
            _repository.SaveChanges();

            Data.User addedDataUser = _repository.Get <Data.User>(x => x.Username == UpdatedUser.Username);
            if (addedDataUser == null)
            {
                // The user should have been inserted into the database, but they were not. (Or failed during insertion)
                return(UserNotFound());
            }

            UpdatedUser = Container_Classes.User.DataUserToUser(addedDataUser, UpdatedUser.Foods);

            // Create the model to return the information to the view.
            UserViewModels model = new UserViewModels();

            model.User = UpdatedUser;

            return(model);
        }
Beispiel #8
0
        public UserViewModels LoginUser(String username, String password)
        {
            // Try and find the username within the database
            Data.User dataUser = _repository.Get <Data.User>(x => x.Username.Equals(username));
            if (dataUser == null)
            {
                return(UserNotFound());
            }
            // Ensure that the passwords match
            if (!dataUser.Password.Equals(password))
            {
                return(UserNotFound());
            }

            Data.Food dataFood = _repository.Get <Data.Food>(x => x.FoodID == dataUser.Food_ID);

            Container_Classes.User containerUser = Container_Classes.User.DataUserToUser(dataUser, dataFood.Food1);

            UserViewModels model = new UserViewModels();

            model.User = containerUser;

            return(model);
        }
Beispiel #9
0
        // Returns the view of all of the events the user is registered for.
        public EventsViewModels RegisterUserForEvent(Container_Classes.Event containerEvent, Container_Classes.User containerUser)
        {
            int foodID = int.Parse(containerUser.Foods);

            // Get the food ID from the database using the containerUser object
            Data.Food dataFood = _repository.Get <Data.Food>(x => x.FoodID == foodID);
            // Ensure that we found the food in the database
            if (dataFood == null)
            {
                return(null);
            }

            // Ensure that the user exists in the database
            Data.User dataUser = Container_Classes.User.UserToDataUser(containerUser, dataFood.FoodID);
            dataUser = _repository.Get <Data.User>(x => x.UserID == dataUser.UserID);

            if (dataUser == null)
            {
                // The user was not found in the database
                return(null);
            }

            // Grab the Category and type from the database so we can read an event from the database
            Data.Category dataCategory = _repository.Get <Data.Category>(x => x.Category1.Equals(containerEvent.Category));
            if (dataCategory == null)
            {
                // We could not find the category in the database
                return(null);
            }

            Data.Type dataType = _repository.Get <Data.Type>(x => x.Type1.Equals(containerEvent.Type));
            if (dataType == null)
            {
                // We could not find the type in the database
                return(null);
            }

            // Ensure that the event exists in the database
            Data.Event dataEvent = Container_Classes.Event.ContainerEventToDataEvent(containerEvent, dataCategory.CategoryID, dataType.TypeID, dataUser.UserID);
            dataEvent = _repository.Get <Data.Event>(x => x.EventID == dataEvent.EventID);

            if (dataEvent == null)
            {
                // The user was not found in the database
                return(null);
            }

            // Prepare the information to be updated in the database
            Data.Registration registration = new Data.Registration();
            registration.User_ID  = dataUser.UserID;
            registration.Event_ID = dataEvent.EventID;

            // Add the registration to the database
            _repository.Add <Data.Registration>(registration);

            _repository.SaveChanges();

            // Get all of the users registered events
            List <Data.Registration> registrations = DatabaseToDataRegistration(_repository.GetAll <Data.Registration>(x => x.User_ID == dataUser.UserID));
            List <Data.Event>        dataEvents    = new List <Data.Event>();

            // Create a list of all events this user is attending
            foreach (Data.Registration dataRegistration in registrations)
            {
                dataEvents.Add(_repository.Get <Data.Event>(x => x.EventID == dataRegistration.Event_ID));
            }

            // Conver the list of dataEvents to containerEvents
            List <Container_Classes.Event> containerEvents = new List <Container_Classes.Event>();

            foreach (Data.Event dataEvent2 in dataEvents)
            {
                dataType     = _repository.Get <Data.Type>(x => x.TypeID == dataEvent2.Type_ID);
                dataCategory = _repository.Get <Data.Category>(x => x.CategoryID == dataEvent2.Category_ID);
                containerEvents.Add(Container_Classes.Event.DataEventToContainerEvent(dataEvent2, dataUser.UserID, dataCategory.Category1, dataType.Type1));
            }

            EventsViewModels model = new EventsViewModels();

            model.Events = containerEvents;

            return(model);
        }