Beispiel #1
0
        private int GetUserAssessment(int idUser, int idHomework)
        {
            var db         = new  DbConfig();
            var sr         = new  Screening();
            var assessment = 0;
            var sqlQuary   = "SELECT assessment " +
                             " FROM h_assessment " +
                             " WHERE id_user   =  "******" and  id_homework = " + sr.GetScr() + idHomework + sr.GetScr();

            foreach (var item in db.GetSqlQuaryData(sqlQuary))
            {
                assessment += Int32.Parse(item[0]);
            }

            return(assessment);
        }
        public async Task <IActionResult> CreateGroup(string title, string description, IFormFile photoGroup = null)
        {
            var idPic        = GetIdForPic();
            var downloadCode = await Picture.Download(idPic, photoGroup);

            if (downloadCode == Picture.DownloadCodes.Fine)
            {
                var db    = new DbConfig();
                var sr    = new Screening();
                var login =
                    HttpContext.Session.GetString("login");
                var userId = UserModel.GetId(login);

                var photoType           = sr.GetScr() + photoGroup.FileName.Split(".").Last() + sr.GetScr();
                var sqlQuaryCreateGroup = $@"
                    INSERT INTO groups(
                        title, description, id_pic , id_founder)
                    VALUES ({sr.GetScr() +title +sr.GetScr()}, 
                            {sr.GetScr() + description + sr.GetScr()}, 
                            {sr.GetScr() + idPic + sr.GetScr() } ,{userId}); ";

                var sqlQuaryCreatePicture = $@"
                    INSERT INTO pictures(guid, type_pic)
                    VALUES ({sr.GetScr() + idPic + sr.GetScr() }, {photoType});";

                var sqlQuaryGetIdGroup = $@"
                    SELECT id 
                        FROM groups 
                    WHERE id_founder = {userId}  
                    ORDER BY id DESC
                    LIMIT 1 ;";

                db.UseSqlQuary(sqlQuaryCreatePicture);
                db.UseSqlQuary(sqlQuaryCreateGroup);
                var groupData = db.GetSqlQuaryData(sqlQuaryGetIdGroup);
                var idGroup   = -1;
                foreach (var item in groupData)
                {
                    idGroup = Convert.ToInt32(item[0]);
                }


                return(await Task.Run(() => RedirectToAction("ShowGroup", new RouteValueDictionary(
                                                                 new { controller = "Group", action = "ShowGroup", idGroup = idGroup }))));
            }
            return(await Task.Run(() => RedirectToAction("Index", new RouteValueDictionary(
                                                             new { controller = "Home", action = "Index" }))));
        }
Beispiel #3
0
        private bool IsRegisterEmail(string Email)
        {
            var db       = new DbConfig();
            var sr       = new Screening();
            var sqlQuary = "select id from users where mail = " + sr.GetScr() + Email + sr.GetScr();
            var userData = db.GetSqlQuaryData(sqlQuary);

            if (userData.Count() > 0)
            {
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        static public int GetId(string login)
        {
            var db = new DbConfig();
            var sr = new Screening();

            var sqlQuary = "select id from users where login = " + sr.GetScr() + login + sr.GetScr();
            var idUser   = -1;

            foreach (var userData in db.GetSqlQuaryData(sqlQuary))
            {
                idUser = Convert.ToInt32(userData[0]);
            }
            return(idUser);
        }
        private Guid GetIdForPic()
        {
            var db       = new DbConfig();
            var sr       = new Screening();
            var NewIdPic = Guid.NewGuid();

            while (true)
            {
                var sqlQuary = $@"  SELECT guid 
                                    From Pictures 
                                WHERE guid = {sr.GetScr() + NewIdPic + sr.GetScr()}";
                var picId    = db.GetSqlQuaryData(sqlQuary);

                if (picId.Count() > 0)
                {
                    NewIdPic = Guid.NewGuid();
                }
                else
                {
                    break;
                }
            }
            return(NewIdPic);
        }
Beispiel #6
0
        public IActionResult UpdateInfopPage()
        {
            var sr        = new Screening();
            var db        = new DbConfig();
            var login     = HttpContext.Session.GetString("login");
            var usersData =
                db.GetSqlQuaryData("SELECT first_name,second_name,picture_profile FROM users " +
                                   " WHERE users.login = " + sr.GetScr() + login + sr.GetScr());
            var userData = new List <string>();

            foreach (var item in usersData)
            {
                userData = item;
            }


            var user = new UserModel();

            user.first_name      = userData[0];
            user.second_name     = userData[1];
            user.picture_profile = userData[2];
            ViewBag.User_data    = user;
            return(View());
        }
Beispiel #7
0
        public async Task <IActionResult> Reg(string _mail, string _login, string _password, string _password2)
        {
            var db = new DbConfig();

            HttpContext.Session.SetString("reg_mail", "" + _mail);
            HttpContext.Session.SetString("reg_login", "" + _login);
            if (_password != _password2)
            {
                return(await Task.Run(() => RedirectToAction("Reg", new { type = 1 })));
            }
            else
            {
                if (_password.Length > 8)
                {
                    var sr      = new Screening();
                    var usersId = GetUserId(_login);
                    if (usersId == -1)
                    {
                        var ex = new Regex("^[0-9A-Za-z]{1}[0-9A-Za-z_-]*@{1}[A-Za-z]+[.][A-Za-z]+$");
                        if (ex.IsMatch(_mail))
                        {
                            if (IsRegisterEmail(_mail))
                            {
                                return(await Task.Run(() => RedirectToAction("Reg", new { type = 3 })));
                            }

                            db.UseSqlQuary("INSERT INTO users(mail,login,password) " +
                                           " VALUES " +
                                           "       (" + sr.GetScr() + _mail + sr.GetScr() +
                                           " ,lower(" + sr.GetScr() + _login + sr.GetScr() +
                                           "),crypt(" + sr.GetScr() + _password + sr.GetScr() + ", gen_salt('bf', 8)))");

                            return(await Task.Run(() => RedirectToAction("Authorization", new{ ex = 3 })));
                        }
                        else
                        {
                            return(await Task.Run(() => RedirectToAction("Reg", new { type = 4 })));
                        }
                    }
                    else
                    {
                        Console.WriteLine("2");
                        return(await Task.Run(() => RedirectToAction("Reg", new { type = 2 })));
                    }
                }
                else
                {
                    return(await Task.Run(() => RedirectToAction("Reg", new { type = 5 })));
                }
            }
        }
        public async Task <IActionResult> SearchGroup(string name = null)
        {
            var sr = new Screening();
            var db = new DbConfig();
            var sqlQuarySelectGroupByName = "";

            if (string.IsNullOrEmpty(name))
            {
                sqlQuarySelectGroupByName = $@"
                SELECT id, title, description, pictures.guid , type_pic 
                    FROM groups inner join pictures on
                        groups.id_pic = pictures.guid 
                ";
            }
            else
            {
                sqlQuarySelectGroupByName = $@"
                SELECT id, title, description, pictures.guid , type_pic 
                    FROM groups inner join pictures on
                        groups.id_pic = pictures.guid  WHERE title = {sr.GetScr() + name + sr.GetScr()}
                ";
            }
            var groups     = new List <GroupModel>();
            var groupsData = db.GetSqlQuaryData(sqlQuarySelectGroupByName);


            foreach (var item in groupsData)
            {
                var group = new GroupModel(item[3], item[4]);
                group.idGroup     = Int32.Parse(item[0]);
                group.title       = item[1];
                group.description = item[2];
                groups.Add(group);
            }
            ViewBag.Groups     = groups;
            ViewBag.SearchName = name;
            return(await Task.Run(() => View()));
        }
        public async Task <IActionResult> AddPost(int idGroup, string title, string text, IFormFile file = null)
        {
            //here need check (is user group )
            //add change to upload file with some material .doc  ect
            // here a early version. Please if u want  upgrade the func  u can do it :)
            // Last date edit 21.06.2020

            var db = new DbConfig();
            var sr = new Screening();

            var sqlQuaryAddPost = $@"
               INSERT INTO public.group_post( id_group, title, description)
	            VALUES ( {sr.GetScr() + idGroup + sr.GetScr()}, 
                         {sr.GetScr() + title + sr.GetScr()},
                         {sr.GetScr() + text + sr.GetScr()});";

            db.UseSqlQuary(sqlQuaryAddPost);

            return(await Task.Run(() => RedirectToAction("ShowGroup", new RouteValueDictionary(
                                                             new { controller = "Group", action = "ShowGroup", idGroup = idGroup }))));
        }
Beispiel #10
0
        public async Task <IActionResult> UpdateInfo(string first_name, string second_name, IFormFile u_file = null)
        {
            string filePath  = "";
            string file_name = "";
            var    sr        = new Screening();
            var    db        = new DbConfig();

            var _login = HttpContext.Session.GetString("login");

            if (_login == "")
            {
                return(RedirectToAction("Authorization", new RouteValueDictionary(
                                            new { controller = "User ", action = "Profile" })));
            }
            else
            {
                if (u_file != null)
                {
                    string [] type = u_file.FileName.Split('.');

                    type[1] = type[1].ToUpper();
                    if ((type[1] == "PNG") || (type[1] == "JPEG") || (type[1] == "JPG"))
                    {
                        string [] type_pic = u_file.FileName.Split('.');
                        Guid      id_pic   = Guid.NewGuid();
                        filePath  = "wwwroot\\Pictures\\" + id_pic + "." + type_pic[1];
                        file_name = "" + id_pic + "." + type_pic[1];

                        Console.WriteLine("2 -- -- -- " + filePath + " -- " + id_pic);
                        Bitmap myBitmap;
                        using (Stream fs = new FileStream(filePath, FileMode.OpenOrCreate))
                        {
                            await u_file.CopyToAsync(fs);

                            Console.WriteLine(fs.Position + "  ---  - - - -- " + u_file.Length);
                            while (fs.Position != u_file.Length)
                            {
                            }                                          // ожидание  загрузки изображения

                            myBitmap = new Bitmap(fs);
                            Console.WriteLine(myBitmap.Width + " -+_+-" + myBitmap.Height);
                        }

                        Image img  = myBitmap;
                        var   im_w = myBitmap.Width;
                        var   im_h = myBitmap.Height;

                        if (im_w > im_h)
                        {
                            im_w = im_h;
                        }
                        else
                        {
                            im_h = im_w;
                        }
                        //XXX  тут надо нормально пререписать как вырезать изображение :)

                        img = img.Crop(new Rectangle(0, 0, im_w, im_h));
                        img.Save(filePath);
                    }
                    else
                    {
                        return(RedirectToAction("UpdateInfo_page", new RouteValueDictionary(
                                                    new { controller = "User", action = "UpdateInfo_page" })));
                    }
                    db.UseSqlQuary("UPDATE users set first_name =  " + sr.GetScr() + first_name
                                   + sr.GetScr() + " ,second_name = " + sr.GetScr() + second_name + sr.GetScr() + "," +
                                   "picture_profile = " + sr.GetScr() + file_name + sr.GetScr() +
                                   " WHERE users.login = "******"UPDATE users set first_name =  " + sr.GetScr() + first_name
                                   + sr.GetScr() + " ,second_name = " + sr.GetScr() + second_name + sr.GetScr() + " " +
                                   " WHERE users.login = "******"Profile", new RouteValueDictionary(
                                        new { controller = "User", action = "Profile" })));
        }