public async Task <IActionResult> CheckPhoneNumber(String phoneNumber)
        {
            if (phoneNumber != null && phoneNumber != "")
            {
                ServiceFriends serviceFriends = new ServiceFriends();

                string clearPhoneNumber = ServicePhoneNumber.LeaveOnlyNumbers(phoneNumber);
                Friend friendUpdate     = null;
                try
                {
                    friendUpdate            = serviceFriends.FindUserByPhoneNumber(clearPhoneNumber);
                    friendUpdate.Voter      = true;
                    friendUpdate.VotingDate = DateTime.Now.Date;
                }
                catch (Exception ex)
                {
                    return(Ok("Пользователь не найден."));
                }

                try
                {
                    await serviceFriends.SaveFriends(friendUpdate);

                    return(Ok("<h4>" + friendUpdate.Name + " " + friendUpdate.PatronymicName + ", поздравляем, Вы зарегистрированы как участник розыгрыша!" + "</h4>"));
                }
                catch (Exception ex)
                {
                    return(Ok("<h4>Не удалось сохранить данные. Обратитесь к администратору!</h4>" + " " + ex.ToString()));
                }
            }
            else
            {
                return(Ok("<h4>Ошибка. Запрос не содержет номера телефона.</h4>"));
            }
        }
        public void CheckMasjsonPhonenumber(string[] phoneNumberDTOs)
        {
            if (phoneNumberDTOs.Length > 0)
            {
                ServiceFriends serviceFriends = new ServiceFriends();

                foreach (string phoneNumber in phoneNumberDTOs)
                {
                    string clearPhoneNumber = ServicePhoneNumber.LeaveOnlyNumbers(phoneNumber);
                    Friend friendUpdate;
                    try
                    {
                        friendUpdate            = serviceFriends.FindUserByPhoneNumber(clearPhoneNumber);
                        friendUpdate.Voter      = true;
                        friendUpdate.VotingDate = DateTime.Now.Date;
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }

                    try
                    {
                        serviceFriends.SaveFriends(friendUpdate);
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
            }
            else
            {
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(long id, [Bind("IdFriend,FamilyName,Name,PatronymicName,DateBirth,Unpinning,CityId,CityDistrictId,ElectoralDistrictId,StreetId,MicroDistrictId,HouseId,Building,Apartment,Telephone,StationId,PollingStationId,Organization,FieldActivityId,PhoneNumberResponsible,DateRegistrationSite,VotingDate,Voter,Adress,TextQRcode,Qrcode,Email,Description,GroupUId,FriendStatusId,OrganizationId")] Friend friend)
        {
            if (id != friend.IdFriend)
            {
                return(NotFound());
            }

            int selectedIndexCityDistrict = 1;

            if (ModelState.IsValid)
            {
                DateTime dateEmpty = new DateTime();
                if (!friend.Name.Equals("") && !friend.FamilyName.Equals("") && friend.DateBirth != dateEmpty)
                {
                    friend.FamilyName = friend.FamilyName != null?friend.FamilyName.Trim() : null;

                    friend.Name = friend.Name != null?friend.Name.Trim() : null;

                    friend.PatronymicName = friend.PatronymicName != null?friend.PatronymicName.Trim() : null;

                    friend.TextQRcode = friend.TextQRcode != null?friend.TextQRcode.Trim() : null;

                    List <Friend> searchFriend = _context.Friend.Include(f => f.GroupU).Where(frnd => frnd.Name.Trim().Equals(friend.Name) && frnd.FamilyName.Trim().Equals(friend.FamilyName) && frnd.PatronymicName.Trim().Equals(friend.PatronymicName) && frnd.DateBirth.Value.Date == friend.DateBirth.Value.Date && frnd.IdFriend != friend.IdFriend).ToList();

                    if (friend.DateBirth.Value.Year < 1900 || friend.DateBirth.Value.Year > 2003)
                    {
                        ModelState.AddModelError("", "Дата рождения меньше 1900 или больше 2003!");
                    }
                    else if (searchFriend.Count == 0)
                    {
                        Friend friendQrText      = null;
                        Friend friendNumberPhone = null;
                        if (friend.TextQRcode != null && !friend.TextQRcode.Trim().Equals(""))
                        {
                            friendQrText = ServiceFriends.FindUserByQRtext(friend.TextQRcode);
                        }
                        if (friend.Telephone != null && !friend.Telephone.Trim().Equals(""))
                        {
                            friendNumberPhone = ServiceFriends.FindUserByPhoneNumber(ServicePhoneNumber.LeaveOnlyNumbers(friend.Telephone));
                        }

                        if ((friendQrText == null || friendQrText.IdFriend == friend.IdFriend) && (friendNumberPhone == null || friendNumberPhone.IdFriend == friend.IdFriend))
                        {
                            User userSave = _context.User.Where(u => u.UserName.Equals(User.Identity.Name)).FirstOrDefault();
                            friend.UserId = userSave.IdUser;
                            //friend.GroupUId = userSave.Groupsusers.First().GroupUId;
                            if (friend.TextQRcode != null && !friend.TextQRcode.Trim().Equals(""))
                            {
                                friend.ByteQrcode = QRcodeServices.GenerateQRcodeFile(friend.FamilyName + " " + friend.Name + " " + friend.PatronymicName, friend.DateBirth.Value.Date.ToString("d"), NameServer + WayController + '?' + NameQRcodeParametrs + '=' + friend.TextQRcode, "png", WayPathQrCodes);
                            }
                            //friend.Qrcode = fileNameQRcode;

                            if (friend.CityId != 1)
                            {
                                friend.CityDistrictId = null;
                                friend.StreetId       = null;
                                friend.HouseId        = null;
                                friend.Apartment      = null;

                                if (friend.Adress != null && friend.Adress.Trim().Length > 5)
                                {
                                    if (friend.Unpinning)
                                    {
                                        Station station;
                                        try
                                        {
                                            station = _context.Station.Find(friend.StationId);
                                        }
                                        catch
                                        {
                                            station = null;
                                        }
                                        if (station != null)
                                        {
                                            try
                                            {
                                                _context.Update(friend);
                                                await _context.SaveChangesAsync();
                                            }
                                            catch (DbUpdateConcurrencyException)
                                            {
                                                if (!FriendExists(friend.IdFriend))
                                                {
                                                    return(NotFound());
                                                }
                                                else
                                                {
                                                    throw;
                                                }
                                            }
                                            return(RedirectToAction(nameof(Index)));
                                        }
                                        else
                                        {
                                            ModelState.AddModelError("", "Не указан участок!");
                                        }
                                    }
                                    else if (!friend.Unpinning)
                                    {
                                        friend.StationId           = null;
                                        friend.ElectoralDistrictId = null;
                                        try
                                        {
                                            _context.Update(friend);
                                            await _context.SaveChangesAsync();
                                        }
                                        catch (DbUpdateConcurrencyException)
                                        {
                                            if (!FriendExists(friend.IdFriend))
                                            {
                                                return(NotFound());
                                            }
                                            else
                                            {
                                                throw;
                                            }
                                        }
                                        return(RedirectToAction(nameof(Index)));
                                    }
                                    else
                                    {
                                        ModelState.AddModelError("", "Не указан участок!");
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError("", "Не корректно заполнено поле с адресом!");
                                }
                            }
                            else
                            {
                                friend.Adress = null;

                                if (friend.HouseId != null && friend.StationId != null)
                                {
                                    House   house;
                                    Station station;
                                    try
                                    {
                                        house   = _context.House.Find(friend.HouseId);
                                        station = _context.Station.Find(friend.StationId);
                                    }
                                    catch
                                    {
                                        house   = null;
                                        station = null;
                                    }
                                    if (house != null && house.Name != null && !house.Name.Equals("") && !house.Name.Equals(" ") && station != null && station.Name != null && !station.Name.Equals(""))
                                    {
                                        try
                                        {
                                            _context.Update(friend);
                                            await _context.SaveChangesAsync();
                                        }
                                        catch (DbUpdateConcurrencyException)
                                        {
                                            if (!FriendExists(friend.IdFriend))
                                            {
                                                return(NotFound());
                                            }
                                            else
                                            {
                                                throw;
                                            }
                                        }
                                        return(RedirectToAction(nameof(Index)));
                                    }
                                    else
                                    {
                                        ModelState.AddModelError("", "Не указан полный адрес или не выбран участок!");
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError("", "Не указан полный адрес или не выбран участок!");
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Участник с данными телефоном или QR-кодом, уже был внесен в списки ранее!");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Участник с данными ФИО и датой рождения уже был внесен ранее в списки в " + searchFriend[0].GroupU.Name + "!");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Не все поля были заполнены");
                }
            }

            List <Groupu> groupsUser = _serviceUser.GetGroupsUser(User.Identity.Name);

            int[] idFieldActivityUser = groupsUser.Select(g => g.FieldActivityId ?? 0).ToArray();
            int[] idOrganizationUser  = groupsUser.Select(g => g.OrganizationId ?? 0).ToArray();

            ViewData["GroupUId"] = new SelectList(groupsUser, "IdGroup", "Name", friend.GroupUId);
            ViewData["CityId"]   = new SelectList(_context.City, "IdCity", "Name", friend.CityId);
            List <CityDistrict> cityDistricts = _context.CityDistrict.Where(cd => cd.CityId == friend.CityId).ToList();

            ViewData["CityDistrictId"]      = new SelectList(cityDistricts, "IdCityDistrict", "Name", friend.CityDistrictId);
            ViewData["ElectoralDistrictId"] = new SelectList(_context.ElectoralDistrict, "IdElectoralDistrict", "Name", friend.ElectoralDistrictId);
            List <Fieldactivity> fieldactivitiesSelect = _context.Fieldactivity.Where(fac => idFieldActivityUser.Contains(fac.IdFieldActivity)).ToList();

            ViewData["FieldActivityId"] = new SelectList(fieldactivitiesSelect, "IdFieldActivity", "Name", friend.FieldActivityId);
            List <Organization> organizationSelect = _context.Organization.Where(org => idOrganizationUser.Contains(org.IdOrganization)).ToList();

            ViewData["OrganizationId"]  = new SelectList(organizationSelect, "IdOrganization", "Name", friend.OrganizationId);
            ViewData["MicroDistrictId"] = new SelectList(_context.Microdistrict, "IdMicroDistrict", "Name", friend.MicroDistrictId);

            List <Street> selectStreets = _context.Street.Where(s => s.CityId == friend.CityDistrictId).ToList();

            selectStreets.Sort((s1, s2) => s1.Name.CompareTo(s2.Name));
            ViewData["StreetId"] = new SelectList(selectStreets, "IdStreet", "Name", friend.StreetId);

            List <House> selectHouse = _context.House.Where(h => h.StreetId == friend.StreetId).ToList();

            selectHouse.Sort((h1, h2) => h1.Name.CompareTo(h2.Name));
            ViewData["HouseId"] = new SelectList(selectHouse, "IdHouse", "Name", friend.HouseId);

            if (friend.CityDistrictId == null || friend.Unpinning)
            {
                List <PollingStation> polingStations = _context.PollingStation.Where(p => p.CityDistrictId == selectedIndexCityDistrict).ToList().GroupBy(p => p.Name).Select(grp => grp.FirstOrDefault()).ToList();
                int[]          stationsId            = polingStations.Select(p => p.StationId ?? 0).ToArray();
                List <Station> stations = _context.Station.Where(s => stationsId.Contains(s.IdStation)).ToList();
                //stations.Sort((s1, s2) => Convert.ToInt32(s1.Name) - Convert.ToInt32(s2.Name));
                stations.Sort();
                stations.Insert(0, new Station {
                    IdStation = 0, Name = ""
                });
                ViewData["StationId"] = new SelectList(stations, "IdStation", "Name", friend.StationId);
            }
            else
            {
                List <PollingStation> polingStations = _context.PollingStation.Where(p => p.CityDistrictId == friend.CityDistrictId).ToList().GroupBy(p => p.Name).Select(grp => grp.FirstOrDefault()).ToList();
                int[]          stationsId            = polingStations.Select(p => p.StationId ?? 0).ToArray();
                List <Station> stations = _context.Station.Where(s => stationsId.Contains(s.IdStation)).ToList();
                //stations.Sort((s1, s2) => Convert.ToInt32(s1.Name) - Convert.ToInt32(s2.Name));
                stations.Sort();
                stations.Insert(0, new Station {
                    IdStation = 0, Name = ""
                });
                ViewData["StationId"] = new SelectList(stations, "IdStation", "Name", friend.StationId);
            }


            ViewData["UserId"]         = new SelectList(_context.User, "IdUser", "UserName", friend.UserId);
            ViewData["FriendStatusId"] = new SelectList(_context.FriendStatus, "IdFriendStatus", "Name", friend.FriendStatusId);

            return(View(friend));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> RegistrationFromTelegram([FromBody] MessageRegisterUser registerUser)
        {
            Friend friend;
            ResponseMessageData responseMessage;
            string numberPhone = registerUser.phoneNumber != null?ServicePhoneNumber.LeaveOnlyNumbers(registerUser.phoneNumber) : null;

            if (numberPhone != null)
            {
                friend = _serviceFriends.FindUserByPhoneNumber(numberPhone);
            }
            else
            {
                responseMessage = new ResponseMessageData {
                    status = " Некорректный номер телефона"
                };
                return(Ok(responseMessage));
            }
            if (friend != null)
            {
                responseMessage = new ResponseMessageData {
                    status = " Участник с данным номером телефона уже зарегистрован!"
                };
                return(Ok(responseMessage));
            }
            else if (_serviceFriends.FindFriendByUserNameMessanger(registerUser.userNameMessanger) != null)
            {
                responseMessage = new ResponseMessageData {
                    status = " С данного аккаунта уже была произведена регистрация ранее!"
                };
                return(Ok(responseMessage));
            }
            else
            {
                DateTime dateRegistration = DateTime.Today;

                FriendDTO friendDTO = new FriendDTO {
                    FamilyName        = registerUser.famileName, Name = registerUser.name, PatronymicName = registerUser.patronimicName,
                    Telephone         = registerUser.phoneNumber, userNameMessanger = registerUser.userNameMessanger,
                    FieldActivityName = registerUser.fieldActivityName, Organization = registerUser.organization,
                    Group             = registerUser.group, LoginUsers = registerUser.user, TextQRcode = registerUser.phoneNumber
                };

                Friend newFriend = null;
                try
                {
                    newFriend = _serviceFriends.CreateFreandMessanger(friendDTO, dateRegistration);
                }
                catch (Exception ex)
                {
                    responseMessage = new ResponseMessageData {
                        status = " Ошибка создания участника."
                    };
                    return(Ok(responseMessage));
                }
                bool save = false;

                if (newFriend != null)
                {
                    try
                    {
                        save = await _serviceFriends.SaveNewFriends(newFriend);
                    }
                    catch (Exception ex)
                    {
                        responseMessage = new ResponseMessageData {
                            status = " Ошибка сохранения данных об участнике."
                        };
                        return(Ok(responseMessage));
                    }
                }

                if (save)
                {
                    responseMessage = new ResponseMessageData {
                        status = " Регистрация прошла успешно!"
                    };

                    if (newFriend.TextQRcode != null && newFriend.ByteQrcode != null)
                    {
                        responseMessage.byteQrcode  = newFriend.ByteQrcode;
                        responseMessage.textMessage = newFriend.TextQRcode;
                    }
                    else if (newFriend.TextQRcode != null)
                    {
                        responseMessage.textMessage = newFriend.TextQRcode;
                    }
                    else
                    {
                        responseMessage.textMessage = " Участник зарегистрирован, но QR код сгенерировать не получилось. Обратитесь пожалуйста к администратору сервиса!";
                    }
                    return(Ok(responseMessage));
                }
                else
                {
                    responseMessage = new ResponseMessageData {
                        status = " Ваши данные не удалось сохранить. Регистрация не выполнена!"
                    };
                    return(Ok(responseMessage));
                }
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AcceptReplyMessageBot([FromBody] MessageData messageData)
        {
            Friend friend;
            ResponseMessageData responseMessage;
            string jsonResponse;
            string numberPhone = messageData.PhoneNumber != null?ServicePhoneNumber.LeaveOnlyNumbers(messageData.PhoneNumber) : null;

            if (numberPhone != null && numberPhone.Length > 10)
            {
                friend = _serviceFriends.FindUserByPhoneNumber(numberPhone);
            }
            else
            {
                responseMessage = new ResponseMessageData {
                    status = "Invalid phone number"
                };
                return(Ok(responseMessage));
            }

            string textQrCode;

            Byte[] byteCode = null;

            if (friend != null)
            {
                textQrCode = friend.TextQRcode;
            }
            else
            {
                responseMessage = new ResponseMessageData {
                    status = "Not found"
                };
                return(Ok(responseMessage));
            }

            if (friend.ByteQrcode != null)
            {
                byteCode = friend.ByteQrcode;
            }

            if (textQrCode != null && byteCode != null)
            {
                responseMessage = new ResponseMessageData {
                    phoneNumber = friend.Telephone, textMessage = textQrCode, byteQrcode = byteCode, status = "Ok"
                };
            }
            else if (textQrCode != null)
            {
                responseMessage = new ResponseMessageData {
                    phoneNumber = friend.Telephone, textMessage = textQrCode
                };
            }
            else
            {
                responseMessage = new ResponseMessageData {
                    textMessage = "Участнику с данным номером телефона не присвоен QR-код!", status = "Ok"
                };
            }
            //jsonResponse = JsonSerializer.Serialize(responseMessage);

            return(Ok(responseMessage));
        }