/// <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");
        }
        public async Task <IActionResult> PutHouse(int id, House house)
        {
            if (id != house.id)
            {
                return(BadRequest());
            }

            _context.Entry(house).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HouseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
 public virtual async Task <int> UpdateModel(T model)
 {
     _logger.LogInformation(@$ "{_serviceName} Update {nameof(T)}", model);
     _context.Entry(model).State = EntityState.Modified;
     _logger.LogInformation(@$ "{_serviceName} Update {nameof(T)} complete", model);
     return(await _context.SaveChangesAsync());
 }
        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));
        }
Esempio n. 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));
        }
Esempio n. 6
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));
        }
Esempio n. 7
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));
        }
Esempio n. 8
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));
        }
Esempio n. 9
0
        public async Task <ActionResult <House> > PostHouse(House house)
        {
            _context.houses.Add(house);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (HouseExists(house.HouseName))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetHouse", new { Hn = house.HouseName }, house));
        }
Esempio n. 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));
        }
Esempio n. 11
0
        public async Task <ServiceResponse> UpdateCounter(CounterViewModel model)
        {
            _logger.LogInformation(@$ "{_serviceName} Update {nameof(Counter)}", model);
            _context.Entry(model).State = EntityState.Modified;
            _logger.LogInformation(@$ "{_serviceName} Update {nameof(Counter)} complete", model);

            var resultUpdate = await _context.SaveChangesAsync();

            if (resultUpdate == 1)
            {
                return(new ServiceResponse()
                {
                    Status = ServiceResponseStatus.Ok,
                    Result = resultUpdate
                });
            }

            return(new ServiceResponse()
            {
                Status = ServiceResponseStatus.NotFound,
                Result = $"Update {nameof(Counter)} id={model.Id} not found"
            });
        }
Esempio n. 12
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            RequirePassword = await _userManager.HasPasswordAsync(user);

            if (RequirePassword)
            {
                if (!await _userManager.CheckPasswordAsync(user, Input.Password))
                {
                    ModelState.AddModelError(string.Empty, "Incorrect password.");
                    return(Page());
                }
            }

            Customer customer = await _context.Customer.FirstOrDefaultAsync(x => x.UserID == user.Id);

            _context.Customer.Remove(customer);
            await _context.SaveChangesAsync();

            var result = await _userManager.DeleteAsync(user);

            var userId = await _userManager.GetUserIdAsync(user);

            if (!result.Succeeded)
            {
                throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'.");
            }

            await _signInManager.SignOutAsync();

            _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId);

            return(Redirect("~/"));
        }
Esempio n. 13
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));
        }
Esempio n. 14
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            List <Profession> availableProfessions = _context.Profession.ToList();

            Professions = availableProfessions.Select(x => new SelectListItem()
            {
                Text = x.Description, Value = x.ProfessionID.ToString()
            }).ToList();
            if (ModelState.IsValid)
            {
                var user = new CustomUser
                {
                    UserName = Input.Email,
                    Email    = Input.Email,
                    Customer = new Customer
                    {
                        Firstname  = Input.Firstname,
                        Lastname   = Input.Lastname,
                        Profession = _context.Profession.Where(x => x.ProfessionID == Input.ProfessionID).FirstOrDefault()
                    }
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                user.Customer.UserID = user.Id;

                await _context.SaveChangesAsync();

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Esempio n. 15
0
 public async Task SaveAsync()
 {
     await _context.SaveChangesAsync();
 }
Esempio n. 16
0
 public async Task <ActionResult <int> > AddReHouse([FromBody] Second_House fi)
 {
     db.Second_Houses.Add(fi);
     return(await db.SaveChangesAsync());
 }
Esempio n. 17
0
 public async Task SaveAsync()
 {
     await db.SaveChangesAsync();
 }