/// <summary>
        /// Добавление нового дома
        /// </summary>
        /// <param name="city">Город</param>
        /// <param name="street">Улица</param>
        /// <param name="number">Номер</param>
        /// <returns>Результат добавления дома</returns>
        public async Task <string> AddHouse(string city, string street, string number)
        {
            if (GetHouseByCityAndStreetAndNumber(city, street, number) != null)
            {
                return("Not add. House Present.");
            }

            var counter = new Counter()
            {
                FactoryNumber        = "None",
                VerificationTimeOver = DateTime.Now,
                Indications          = new List <Indication>()
                {
                    new Indication()
                    {
                        CurrentIndication  = 0,
                        FillingTime        = DateTime.Now,
                        PreviousIndication = 0
                    }
                }
            };

            var house = new House()
            {
                City = city, Street = street, Number = number, Counter = counter
            };

            _context.Add(counter);
            _context.Add(house);
            await _context.SaveChangesAsync();

            return("OK");
        }
Пример #2
0
 public IActionResult Register(Reg newUser)
 {
     System.Console.WriteLine("-----------------------------------");
     System.Console.WriteLine(newUser);
     if (ModelState.IsValid)
     {
         // If a User exists with provided email
         if (dbContext.Users.Any(u => u.Email == newUser.Email))
         {
             // Manually add a ModelState error to the Email field, with provided
             // error message
             ModelState.AddModelError("Email", "Email already in use!");
             return(View("Log-Reg"));
             // You may consider returning to the View at this point
         }
         else
         {
             // Initializing a PasswordHasher object, providing our User class as its
             PasswordHasher <Reg> Hasher = new PasswordHasher <Reg>();
             newUser.Password = Hasher.HashPassword(newUser, newUser.Password);
             dbContext.Add(newUser);
             dbContext.SaveChanges();
             HttpContext.Session.SetInt32("UId", newUser.UserId);
             HttpContext.Session.SetString("UName", newUser.Username);
         }
         return(RedirectToAction("Main", "Main"));
     }
     else
     {
         System.Console.WriteLine("-----------------------------------");
         System.Console.WriteLine("User not created");
         return(View("Log-Reg"));
     }
 }
Пример #3
0
        public async Task <IActionResult> Create([Bind("LocationID,Name,Place,Adress")] Location location)
        {
            if (ModelState.IsValid)
            {
                _context.Add(location);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("ID,Characteristic,Title,Price,SuitesNumber,Size,Cep,City,District,PhoneNumber,ParkingSpace,Leasing,Sale")] House house)
        {
            if (ModelState.IsValid)
            {
                _context.Add(house);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(house));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("ProfessionID,Description")] Profession profession)
        {
            if (ModelState.IsValid)
            {
                _context.Add(profession);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(profession));
        }
Пример #6
0
        public async Task <IActionResult> Create(CreateRoomViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(viewModel.Room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            viewModel.Locations = new SelectList(_context.Location, "LocationID", "NameAndPlace", viewModel.Room.LocationID);
            return(View(viewModel));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("CustomerID,Firstname,Lastname,ProfessionID,UserID")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserID"]       = new SelectList(_context.Users, "Id", "Id", customer.UserID);
            ViewData["ProfessionID"] = new SelectList(_context.Profession, "ProfessionID", "Description", customer.ProfessionID);
            return(View(customer));
        }
Пример #8
0
        public IActionResult Post([FromBody] Interior entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (entity.DefinitionID == 0)
            {
                ModelState.AddModelError <Interior>(e => e.Definition, "Could not determine type of interior, please specify the type.");
                return(BadRequest(ModelState));
            }

            entity.ID = 0;
            _context.Add(entity);
            _context.SaveChanges();
            return(Created(entity));
        }
Пример #9
0
        public async Task <IActionResult> Create(CreateInvoiceViewModel viewModel)
        {
            viewModel.Invoice = new Invoice();

            viewModel.Invoice.Date       = DateTime.Today;
            viewModel.Invoice.EndDate    = DateTime.Today.AddDays(14);
            viewModel.Invoice.Paid       = false;
            viewModel.Invoice.CustomerID = viewModel.SelectedCustomer ?? -1;

            double Total = 0;

            if (ModelState.IsValid)
            {
                _context.Add(viewModel.Invoice);
                await _context.SaveChangesAsync();

                List <ReservationInvoice> newInvoices = new List <ReservationInvoice>();
                foreach (int reservationID in viewModel.SelectedReservations)
                {
                    Reservation reservation = _context.Reservation.Find(reservationID);
                    Total = Total + reservation.Price;
                    newInvoices.Add(new ReservationInvoice
                    {
                        ReservationID = reservationID,
                        InvoiceID     = viewModel.Invoice.InvoiceID
                    });
                }

                viewModel.Invoice.TotalPrice = Total;
                _context.Update(viewModel.Invoice);
                await _context.SaveChangesAsync();

                Invoice invoice = await _context.Invoice.Include(x => x.ReservationInvoices)
                                  .SingleOrDefaultAsync(x => x.InvoiceID == viewModel.Invoice.InvoiceID);

                invoice.ReservationInvoices.AddRange(newInvoices);
                _context.Update(invoice);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            //zaken terug opvullen
            return(View(viewModel));
        }
Пример #10
0
        public async Task <IActionResult> Create(CreateReservationViewModel viewModel)
        {
            viewModel.Reservation = new Reservation();

            ClaimsPrincipal currentUser   = this.User;
            var             currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;

            List <Customer> customers = await _context.Customer.ToListAsync();

            Customer currentCustomer = new Customer();

            foreach (Customer customer in customers)
            {
                if (customer.UserID == currentUserID)
                {
                    currentCustomer = customer;
                }
            }

            viewModel.Reservation.CustomerID = currentCustomer.CustomerID;
            viewModel.Reservation.RoomID     = viewModel.SelectedRoom ?? -1;
            viewModel.Reservation.Date       = viewModel.SelectedDate ?? default;
            viewModel.Reservation.PeriodID   = viewModel.SelectedPeriod ?? -1;

            Room room = _context.Room.Find(viewModel.SelectedRoom);

            if (ModelState.IsValid)
            {
                viewModel.Reservation.Price = room.PriceHour * 2;
                _context.Add(viewModel.Reservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Own)));
            }
            viewModel.LocationList = new SelectList(_context.Location, "LocationID", "NameAndPlace");
            viewModel.RoomList     = new SelectList(_context.Room, "RoomID", "Description");
            viewModel.PeriodList   = new SelectList(_context.Period, "PeriodID", "Hour");
            return(View(viewModel));
        }
Пример #11
0
        private void AddTestData(HouseContext context)
        {
            // NOTE: save changes inbetween ensure we have IDs for our entities

            // Add interior definitions for chairs and tables:

            // class Chair
            // {
            //     public string Manufacturer {get;set;}
            //     public string Model {get;set;}
            //     public int Year {get;set;}
            //     public double Weight {get;set;}
            // }

            var chairDefinition = new InteriorDefinition
            {
                Name = "Chair",
            };

            context.Add(chairDefinition);
            context.SaveChanges();

            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Manufacturer",
                PropertyType = InteriorPropertyType.String,
                PropertyName = nameof(IUserDefinedPropertyBag.StringProperty1),
                DefinitionID = chairDefinition.ID,
                Definition   = chairDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Model",
                PropertyType = InteriorPropertyType.String,
                PropertyName = nameof(IUserDefinedPropertyBag.StringProperty2),
                DefinitionID = chairDefinition.ID,
                Definition   = chairDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Year",
                PropertyType = InteriorPropertyType.Int,
                PropertyName = nameof(IUserDefinedPropertyBag.IntProperty1),
                DefinitionID = chairDefinition.ID,
                Definition   = chairDefinition,
            });

            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Weight",
                PropertyType = InteriorPropertyType.Double,
                PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty1),
                DefinitionID = chairDefinition.ID,
                Definition   = chairDefinition,
            });
            context.SaveChanges();


            // class Table
            // {
            //     public string Manufacturer {get;set;}
            //     public string Model {get;set;}
            //     public int ExpansionPanels {get;set;}
            //     public int SuitablePersonCount {get;set;}
            //     public double Width {get;set;}
            //     public double Height {get;set;}
            //     public double Depth {get;set;}
            // }

            var tableDefinition = new InteriorDefinition
            {
                Name = "Table",
            };

            context.Add(tableDefinition);
            context.SaveChanges();

            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Manufacturer",
                PropertyType = InteriorPropertyType.String,
                PropertyName = nameof(IUserDefinedPropertyBag.StringProperty1),
                DefinitionID = tableDefinition.ID,
                Definition   = tableDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Model",
                PropertyType = InteriorPropertyType.String,
                PropertyName = nameof(IUserDefinedPropertyBag.StringProperty2),
                DefinitionID = tableDefinition.ID,
                Definition   = tableDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "ExpansionPanels",
                PropertyType = InteriorPropertyType.Int,
                PropertyName = nameof(IUserDefinedPropertyBag.IntProperty1),
                DefinitionID = tableDefinition.ID,
                Definition   = tableDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "SuitablePersonCount",
                PropertyType = InteriorPropertyType.Int,
                PropertyName = nameof(IUserDefinedPropertyBag.IntProperty2),
                DefinitionID = tableDefinition.ID,
                Definition   = tableDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Width",
                PropertyType = InteriorPropertyType.Double,
                PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty1),
                DefinitionID = tableDefinition.ID,
                Definition   = tableDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Height",
                PropertyType = InteriorPropertyType.Double,
                PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty2),
                DefinitionID = tableDefinition.ID,
                Definition   = tableDefinition,
            });
            context.Add(new InteriorPropertyDefinition
            {
                Name         = "Depth",
                PropertyType = InteriorPropertyType.Double,
                PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty3),
                DefinitionID = tableDefinition.ID,
                Definition   = tableDefinition,
            });
            context.SaveChanges();

            // Add some test houses and rooms (random data)

            var deskManufacturers = new[] { "Desk Inc.", "Desktopia", "Desk4You", "WeLoveDesks" };
            var deskModels        = new[] { "Dining Table", "Couch Table", "Pool Table", "Table Football Table", "Poker Table" };

            var chairManufacturers = new[] { "Chair Inc.", "Chairtopia", "Chair4You", "WeLoveChairs" };
            var chairModels        = new[] { "Armchair", "Rocking Chair", "Stool", "Wheelchair", "Deckchair" };

            var random = new Random();

            for (int houseIndex = 0; houseIndex < random.Next(1, 5); houseIndex++)
            {
                var house = new House
                {
                    Name    = "House " + houseIndex,
                    Address = "Main Street " + random.Next(1, 100)
                };
                context.Add(house);
                context.SaveChanges();

                for (int roomIndex = 0; roomIndex < random.Next(1, 10); roomIndex++)
                {
                    var room = new Room
                    {
                        Name    = house.Name + " - Room " + roomIndex,
                        House   = house,
                        HouseID = house.ID
                    };
                    context.Add(room);
                    context.SaveChanges();

                    for (int tableIndex = 0; tableIndex < random.Next(1, 5); tableIndex++)
                    {
                        var table = new Interior
                        {
                            Definition   = tableDefinition,
                            DefinitionID = tableDefinition.ID,
                            Room         = room,
                            RoomId       = room.ID,

                            StringProperty1 = deskManufacturers[random.Next(deskManufacturers.Length)],
                            StringProperty2 = deskModels[random.Next(deskModels.Length)],
                            IntProperty1    = random.Next(0, 2),         // ExpansionPanels
                            IntProperty2    = random.Next(4, 10),        // SuitablePersonCount
                            DoubleProperty1 = random.NextDouble() * 300, // Width (0-300cm)
                            DoubleProperty2 = random.NextDouble() * 120, // Height (0-120cm)
                            DoubleProperty3 = random.NextDouble() * 800, // Depth (0-800cm)
                        };
                        context.Add(table);
                    }
                    context.SaveChanges();

                    for (int chairIndex = 0; chairIndex < random.Next(1, 10); chairIndex++)
                    {
                        var chair = new Interior
                        {
                            Definition   = chairDefinition,
                            DefinitionID = chairDefinition.ID,
                            Room         = room,
                            RoomId       = room.ID,

                            StringProperty1 = chairManufacturers[random.Next(deskManufacturers.Length)],
                            StringProperty2 = chairModels[random.Next(deskModels.Length)],
                            IntProperty1    = random.Next(2000, DateTime.Now.Year + 1), // Year
                            DoubleProperty1 = 500 + random.NextDouble() * 500,          // Weight (500-1000g)
                        };
                        context.Add(chair);
                    }
                    context.SaveChanges();
                }
            }
        }
Пример #12
0
 public IActionResult Message(Message newMsg)
 {
     dbContext.Add(newMsg);
     dbContext.SaveChanges();
     return(RedirectToAction("Community"));
 }