public async Task <IActionResult> ApproveResident(int id, Residents r)
        {
            _log4net.Info("Update Resiednt Wallert For Resident With Id " + id + " Was Called !!");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var ApprovedResident = await _context.ApproveResident(id);

                return(Ok(ApprovedResident));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Beispiel #2
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var sameFoods       = new Storage();
            var foodDataStorage = new DataStorage("foods");

            sameFoods.Foods = foodDataStorage.LoadData(sameFoods.Foods);

            var samePersons         = new Residents();
            var customerDataStorage = new DataStorage("customers");

            samePersons.Customers = customerDataStorage.LoadData(samePersons.Customers);

            var dialog = new DialogInShop(
                new StorageOperation(sameFoods, new Logger(), foodDataStorage, new MemoryCache <IFoodable>(), new CurrencyExchanger()),
                new ResidentsOperation(samePersons, new Logger(), customerDataStorage, new MemoryCache <IPersonable>())
                );
            await dialog.DialogStartWorkingAsync();
        }
        public ActionResult Create([Bind(Include = "Id,Passport,Name,Patronymic,Surname,IdCity,SettlementDate,IdRoom,IsEvicted")] Residents residents)
        {
            if (string.IsNullOrEmpty(residents.Passport) || residents.Passport.Length != 10)
            {
                ModelState.AddModelError("Patronymic", "Некорректный паспорт");
            }
            if (string.IsNullOrEmpty(residents.Name))
            {
                ModelState.AddModelError("Name", "Некорректное имя");
            }
            if (string.IsNullOrEmpty(residents.Patronymic))
            {
                ModelState.AddModelError("Patronymic", "Некорректное отчество");
            }
            if (string.IsNullOrEmpty(residents.Surname))
            {
                ModelState.AddModelError("Surname", "Некорректное фамилия");
            }

            Rooms room = db.Rooms.Find(residents.IdRoom);

            if (room?.FreePlace == 0)
            {
                ModelState.AddModelError("IdRoom", "В номере нет свободных мест");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    db.Residents.Add(residents);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    return(View("Error"));
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.IdCity = new SelectList(db.Cities, "Id", "City", residents.IdCity);
            ViewBag.IdRoom = new SelectList(db.Rooms, "Id", "Number", residents.IdRoom);
            return(View(residents));
        }
Beispiel #4
0
        public async Task WriteMetadataToFolderAsync()
        {
            Activities.Sort(delegate(Activity x, Activity y)
            {
                if (x.Name == null && y.Name == null)
                {
                    return(0);
                }
                else if (x.Name == null)
                {
                    return(-1);
                }
                else if (y.Name == null)
                {
                    return(1);
                }
                else
                {
                    return(x.Name.CompareTo(y.Name));
                }
            });
            Residents.Sort(delegate(Resident x, Resident y)
            {
                if (x.Name == null && y.Name == null)
                {
                    return(0);
                }
                else if (x.Name == null)
                {
                    return(-1);
                }
                else if (y.Name == null)
                {
                    return(1);
                }
                else
                {
                    return(x.Name.CompareTo(y.Name));
                }
            });
            StorageFile datasetMetaFile = await Folder.CreateFileAsync("dataset.json", CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteTextAsync(datasetMetaFile, JsonConvert.SerializeObject(this, Formatting.Indented));
        }
        public async Task <IActionResult> UpdateResidentWallet(int id, Residents item)
        {
            _log4net.Info("Update Resiednt Wallert For Resident With Id " + id + " Was Called !!");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                int wallet       = Convert.ToInt32(item.ResidentWallet);
                var updateWallet = await _context.UpdateResidentWallet(id, wallet);

                return(Ok(updateWallet));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Beispiel #6
0
        //Post New  User
        public async void SignUpResidentUsersAsync(LoginSignUp loginSignUp, Residents residents)
        {
            loginSignUp.Role = "user";
            HttpResponseMessage response1 = await client.PostAsJsonAsync("users", loginSignUp);

            if (!response1.IsSuccessStatusCode)
            {
                ////Setting the data to the model
                //return loginDetailsDB = await response.Content.ReadAsAsync<List<LoginSignUp>>();
                Console.WriteLine("Internal server Error");
            }
            HttpResponseMessage response2 = await client.PostAsJsonAsync("userresident", residents);

            if (!response2.IsSuccessStatusCode)
            {
                Console.WriteLine("Internal server Error");
            }
            //return loginDetailsDB = null;
        }
        public async Task <IActionResult> UpdateIsFreeHouse(Residents resident)
        {
            int houseNo = (int)resident.ResidentHouseNo;

            _log4net.Info("Update Is Free Was Called !!");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var updateIsFree = await _context.UpdateIsFreeHouse(houseNo);

                _log4net.Info("Update Is Free for House No. " + resident.ResidentHouseNo + " Was Called !!");
                return(Ok(updateIsFree));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> Add([FromBody] PlanetResponseViewModel planet)
        {
            var(Name, RotationPeriod, OrbitalPeriod, Diameter, Climate, Gravity, Terrain, SurfaceWater, Population, Residents, Films) = planet;
            var newPlanet = new Planet
            {
                Name           = Name,
                RotationPeriod = RotationPeriod,
                OrbitalPeriod  = OrbitalPeriod,
                Diameter       = Diameter,
                Climate        = Climate,
                Gravity        = Gravity,
                Terrain        = Terrain,
                SurfaceWater   = SurfaceWater,
                Population     = Population
            };

            if (Films != null)
            {
                var planetFilms = Films.Select(f => new FilmPlanet {
                    PlanetId = newPlanet.Id, FilmId = f.Id
                }).ToList();
                newPlanet.Films = planetFilms;
            }
            if (Residents != null)
            {
                var planetResidents = Residents.Select(p => new People {
                    Id = p.Id
                }).ToList();
                newPlanet.Residents = planetResidents;
            }
            bool planetAdded = await _planetRepository.Add(newPlanet);

            if (planetAdded)
            {
                return(Ok(new { status = "success", data = "planet added" }));
            }
            return(Ok(new { status = "error", data = "error adding planet" }));
        }
Beispiel #9
0
 public async Task <bool> PostResident(Residents res, int id)
 {
     return(await repository.PostResidentRep(res, id));
 }
        public async Task <IActionResult> Login(LoginDetails loginDetails)
        {
            //string token;
            using (var httpClient = new HttpClient())
            {
                StringContent content = new StringContent(JsonConvert.SerializeObject(loginDetails), Encoding.UTF8, "application/json");
                try
                {
                    using (var response = await httpClient.PostAsync("https://localhost:44388/api/Login/AuthenicateUser", content))
                    {
                        if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                        {
                            _log4net.Info("Login Was Done With Email " + loginDetails.Username + " But the Credentials Were Wrong !!");
                            ViewBag.message = "Invalid User";
                        }
                        else
                        {
                            _log4net.Info("Login Was Done With Email " + loginDetails.Username + " And the Right Password !!");
                            if (loginDetails.LoginType == "Resident")
                            {
                                Residents resident = new Residents();
                                try
                                {
                                    using (var client = new HttpClient())
                                    {
                                        client.BaseAddress = new Uri(baseUrlForResidentApi);
                                        client.DefaultRequestHeaders.Clear();
                                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                        HttpResponseMessage Res = await client.GetAsync("api/Resident/GetResidentByMail/" + loginDetails.Username);

                                        if (Res.IsSuccessStatusCode)
                                        {
                                            var Response = Res.Content.ReadAsStringAsync().Result;
                                            resident = JsonConvert.DeserializeObject <Residents>(Response);
                                            HttpContext.Session.SetInt32("UserID", resident.ResidentId);
                                            return(RedirectToAction("ResidentDashboard", "Resident"));
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    ViewBag.Message = "Resident API Not Reachable. Please Try Again Later.";
                                }
                            }
                            if (loginDetails.LoginType == "Employee")
                            {
                                Employees employee = new Employees();
                                try
                                {
                                    using (var client = new HttpClient())
                                    {
                                        client.BaseAddress = new Uri(baseUrlForEmployeeAPI);
                                        client.DefaultRequestHeaders.Clear();
                                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                        HttpResponseMessage Res = await client.GetAsync("api/Employees/GetEmployeeByMail/" + loginDetails.Username);

                                        if (Res.IsSuccessStatusCode)
                                        {
                                            var Response = Res.Content.ReadAsStringAsync().Result;
                                            employee = JsonConvert.DeserializeObject <Employees>(Response);
                                            if (employee.EmployeeDept == "Security")
                                            {
                                                HttpContext.Session.SetInt32("UserID", employee.EmployeeId);
                                                return(RedirectToAction("SecurityDashboard", "Security"));
                                            }
                                            else
                                            {
                                                HttpContext.Session.SetInt32("UserID", employee.EmployeeId);
                                                return(RedirectToAction("UtilityDashboard", "Utility"));
                                            }
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    ViewBag.Message = "Employee API Not Reachable. Please Try Again Later.";
                                }
                            }
                            if (loginDetails.LoginType == "Admin")
                            {
                                return(RedirectToAction("SecurityDashboard", "Admin"));
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    ViewBag.Message = "Login API not Loaded. Please Try Later.";
                }
                return(View());
            }
        }
Beispiel #11
0
        public Residents GetResidentById(int id)
        {
            Residents item = _context.Residents.Find(id);

            return(item);
        }
Beispiel #12
0
 public bool PostResident(Residents res, int id)
 {
     return(Repository.PostResidentRep(res, id));
 }
Beispiel #13
0
        public Residents GetResidentByMail(string mail)
        {
            Residents item = _context.Residents.Single(res => res.ResidentEmail == mail);

            return(item);
        }
Beispiel #14
0
 // Метод для додавання нового запису реєстрації.
 public void AddRegRec(RegRecord regRecord)
 {
     Residents.Add(regRecord.Resident);
     regRecord.Room.Occupied = true;
     RegRecords.Add(regRecord);
 }
Beispiel #15
0
        // Метод для завантаження тестових даних.
        public void FillTestData(int n)
        {
            // Номери
            Rooms.Clear();
            var noImage = new Bitmap(Path.GetFullPath("empty.png"));

            for (int i = 0; i < n; i++)
            {
                Rooms.Add(new Room()
                {
                    ActualResidents = 1,
                    Occupied        = true,
                    Floor           = (i % 6) + 1,
                    Number          = (i % 20) + 1,
                    Price           = i + 600,
                    Image           = noImage
                });
            }
            // Постояльці
            Residents.Clear();
            for (int i = 0; i < n; i++)
            {
                Residents.Add(new Resident()
                {
                    Surname   = $"ResidentSurname{i}",
                    Name      = $"ResidentName{i}",
                    BirthDate = DateTime.Now - TimeSpan.FromDays(i),
                    Gender    = "-",
                    Phone     = "123456789",
                    Email     = "*****@*****.**"
                });
            }
            // Записи реєстрацій
            RegRecords.Clear();
            for (int i = 0; i < n; i++)
            {
                RegRecords.Add(
                    new RegRecord(
                        Rooms[i],
                        Residents[i],
                        DateTime.Today,
                        DateTime.Today + TimeSpan.FromDays(i + 1)));
            }
            // Гості
            Guests.Clear();
            for (int i = 0; i < n; i++)
            {
                Guests.Add(new Guest()
                {
                    Login         = $"Name{i}",
                    ArrivalDate   = DateTime.Today - TimeSpan.FromDays(i + 1),
                    DepartureDate = DateTime.Today
                });
            }
            // Відгуки
            Reviews.Clear();
            for (int i = 0; i < n; i++)
            {
                Reviews.Add(new Review
                {
                    Guest = Guests[i],
                    Text  = $"Text{i}"
                });
            }
        }
Beispiel #16
0
        public IActionResult Register(Residents u, string[] box)
        {
            if (ModelState.IsValid)
            {
                if (u.Usertype == "Other")
                {
                    u.Permission = String.Join(",", box);
                    if (string.IsNullOrEmpty(u.Permission))
                    {
                        lc.Residents.Remove(u);

                        ModelState.Clear();
                        ModelState.AddModelError("", "you need to select permission for Other user");
                    }
                    else
                    {
                        u.Permission = String.Join(",", box);

                        string email = u.Email;
                        Regex  regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                        Match  match = regex.Match(email);
                        if (match.Success)
                        {
                            u.Email = match.ToString();


                            string strmsg = string.Empty;
                            byte[] encode = new byte[u.Password.Length];
                            encode     = Encoding.UTF8.GetBytes(u.Password);
                            strmsg     = Convert.ToBase64String(encode);
                            u.Password = strmsg;



                            lc.Residents.Add(u);

                            var foo      = lc.Residents.Where(v => v.Username == u.Username).ToList();
                            var foocount = foo.Count();
                            if (foocount == 0)
                            {
                                lc.SaveChanges();
                                ModelState.Clear();
                                ViewBag.Message = "User is successfully registered.";
                            }

                            else
                            {
                                ModelState.Clear();
                                ViewBag.Message = "user already exists please select another one";
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "incorrect email format correct format is [email protected]");
                        }
                    }
                }



                else
                {
                    u.Permission = String.Join(",", box);

                    string email = u.Email;
                    Regex  regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                    Match  match = regex.Match(email);
                    if (match.Success)
                    {
                        u.Email = match.ToString();


                        string strmsg = string.Empty;
                        byte[] encode = new byte[u.Password.Length];
                        encode     = Encoding.UTF8.GetBytes(u.Password);
                        strmsg     = Convert.ToBase64String(encode);
                        u.Password = strmsg;



                        lc.Residents.Add(u);

                        var foo      = lc.Residents.Where(v => v.Username == u.Username).ToList();
                        var foocount = foo.Count();
                        if (foocount == 0)
                        {
                            lc.SaveChanges();
                            ModelState.Clear();
                            ViewBag.Message = "User is successfully registered.";
                        }

                        else
                        {
                            ModelState.Clear();
                            ViewBag.Message = "user already exists please select another one";
                        }
                    }

                    else
                    {
                        ModelState.AddModelError("", "incorrect email format correct format is [email protected]");
                    }
                }
            }
            //var addr = new System.Net.Mail.MailAddress(u.Email);
            //string aa = addr.Address;


            //string decryptpwd = string.Empty;
            //UTF8Encoding encodepwd = new UTF8Encoding();
            //Decoder Decode = encodepwd.GetDecoder();
            //byte[] todecode_byte = Convert.FromBase64String(strmsg);
            //int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            //char[] decoded_char = new char[charCount];
            //Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            //decryptpwd = new String(decoded_char);

            //TempData["dcr"] = decryptpwd;

            return(View());
        }
 public ResidentsNode(Residents residentsValue, ResidentsNode nextObjectAddress)
 {
     ResidentsData = residentsValue;
     NextObject    = nextObjectAddress;
 }