Exemplo n.º 1
0
        public static void OrderIsDone(int idOrder)
        {
            var entity = new sovadb001Entities0();

            entity.orders.First(t => t.IdOrder == idOrder).isDone = true;
            entity.SaveChanges();
        }
Exemplo n.º 2
0
        public static void AddUser(user us)
        {
            var entity = new sovadb001Entities0();

            entity.users.Add(us);
            entity.SaveChanges();
        }
Exemplo n.º 3
0
        public static void ChangeRole(int roleid, int idUser)
        {
            var entity = new sovadb001Entities0();

            entity.users.First(t => t.Id == idUser).roleid = roleid;
            entity.SaveChanges();
        }
Exemplo n.º 4
0
        public static void AddDoc(document doc)
        {
            var entity = new sovadb001Entities0();

            entity.documents.Add(doc);
            entity.SaveChanges();
        }
Exemplo n.º 5
0
        public static void AddDocSpec(documentSpecialization docSpec)
        {
            var entity = new sovadb001Entities0();

            entity.documentSpecializations.Add(docSpec);
            entity.SaveChanges();
        }
Exemplo n.º 6
0
        public static void AddApplication(order Order)
        {
            var entity = new sovadb001Entities0();

            entity.orders.Add(Order);
            entity.SaveChanges();
        }
Exemplo n.º 7
0
        public static List <translator> GetTranslators(int idOrders)
        {
            var               entity      = new sovadb001Entities0();
            order             ord         = GetOrder(idOrders);
            List <translator> tr          = new List <translator>();
            List <translator> translators = entity.translators.ToList();

            foreach (var t in translators)
            {
                bool flag = false;
                List <specialization> spec = GetSpecialization(t.prices.ToList());
                foreach (var o in ord.documentSpecializations)
                {
                    flag = false;
                    foreach (var x  in spec)
                    {
                        if (x.IdSpecialization == (o.IdSpecialization))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        break;
                    }
                }
                if (flag)
                {
                    tr.Add(t);
                }
            }
            return(tr);
        }
Exemplo n.º 8
0
        public ActionResult Save(RegisterApplicationForm doc)
        {
            var entity = new sovadb001Entities0();

            order norder = new order();

            //entity.orders.Add(norder);


            int[] specComplexity = new int[doc.spec.Length + 1];
            int   i = 1;

            specComplexity[0] = (int)DataBase.GetSpecialization(doc.Language).complexity;
            documentSpecialization dc = new documentSpecialization();

            dc.IdSpecialization = DataBase.GetSpecialization(doc.Language).IdSpecialization;
            entity.documentSpecializations.Add(dc);
            foreach (var spec in doc.spec)
            {
                specComplexity[i] = (int)DataBase.GetSpecialization(spec).complexity;
                i++;
                documentSpecialization ndocSpec = new documentSpecialization();
                //ndocSpec.order = norder;
                ndocSpec.IdOrder = norder.IdOrder;
                // ndocSpec.specialization = DataBase.GetSpecialization(spec);
                ndocSpec.IdSpecialization = DataBase.GetSpecialization(spec).IdSpecialization;

                //DataBase.AddDocSpec(ndocSpec);

                entity.documentSpecializations.Add(ndocSpec);
                // norder.documentSpecializations.Add(ndocSpec);
            }


            norder.dateOfCompletion = DateTime.Now;
            norder.name             = doc.name;
            norder.description      = doc.description;
            norder.deadline         = doc.deadline;
            user iduser = auth.AuthHelper.GetUser(HttpContext);

            if (iduser.roleid == 1 && doc.userId != 0)
            {
                norder.idUser = doc.userId;
            }
            else
            {
                norder.idUser = auth.AuthHelper.GetUser(HttpContext).Id;
            }
            norder.isDone     = false;
            norder.inProgress = false;
            //DataBase.AddApplication(norder);
            entity.orders.Add(norder);
            entity.SaveChanges();

            return(RedirectToAction("Index", "Home"));
            // }
        }
Exemplo n.º 9
0
        public ActionResult ViewOrder(int idOrder, int idTranslator)
        {
            sovadb001Entities0 db = new sovadb001Entities0();

            DataBase.AddQueue(idOrder, idTranslator);
            db.orders.First(t => t.IdOrder == idOrder).totalCost  = DataBase.GetCost(idOrder, DataBase.GetTranslator(idTranslator));
            db.orders.First(t => t.IdOrder == idOrder).inProgress = true;
            return(RedirectToAction("ProcessingOfApplication"));
        }
Exemplo n.º 10
0
        public static List <specialization> GetSpecialization(List <price> prices)
        {
            var entity = new sovadb001Entities0();
            List <specialization> spec = new List <specialization>();

            foreach (var p in prices)
            {
                spec.Add(GetSpecialization(p.IdSpecialization));
            }
            return(spec);
        }
Exemplo n.º 11
0
        public static void  AddPrice(int idSpec, int IdUser, double pricespec)
        {
            var   entity = new sovadb001Entities0();
            price np     = new price();

            np.IdSpecialization = idSpec;
            np.IdTranslator     = entity.translators.First(t => t.IdUser == IdUser).IdTranslator;
            np.price1           = pricespec;
            entity.prices.Add(np);
            entity.SaveChanges();
        }
Exemplo n.º 12
0
        public static int AddSpecialization(string name, bool isL, int complexity)
        {
            var            entity = new sovadb001Entities0();
            specialization spec   = new specialization();

            spec.name       = name;
            spec.isLanguage = isL;
            spec.complexity = complexity;
            entity.specializations.Add(spec);
            entity.SaveChanges();
            return(entity.specializations.First(t => t.name == name).IdSpecialization);
        }
Exemplo n.º 13
0
        public static bool isAppUser(int idApp, int idUser)
        {
            var entity = new sovadb001Entities0();
            var ord    = entity.orders.First(t => t.IdOrder == idApp);

            if (ord != null)
            {
                if (entity.users.First(t => t.Id == ord.idUser) != null)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 14
0
        public static user GetUser(HttpContext httpContext)
        {
            sovadb001Entities0 db = new sovadb001Entities0();
            var authCookie        = httpContext.Request.Cookies["__AUTH"];

            if (authCookie != null)
            {
                user user = DataBase.GetUserByCookeis(authCookie.Value);

                return(user);
            }

            return(null);
        }
Exemplo n.º 15
0
        public static user GetUser(int id)
        {
            var  entity = new sovadb001Entities0();
            user user   = entity.users.FirstOrDefault(u => u.Id == id);

            if (user != null)
            {
                user.password = "";
                return(user);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 16
0
        public static void AddQueue(int idOrder, int idTranslator)
        {
            var   entity = new sovadb001Entities0();
            queue nqueue = new queue();

            nqueue.IdTranslator = idTranslator;
            nqueue.IdOrder      = idOrder;
            nqueue.cost         = DataBase.GetCost(idOrder, GetTranslator(idTranslator));
            entity.queues.Add(nqueue);


            entity.orders.First(t => t.IdOrder == idOrder).inProgress = true;
            entity.orders.First(t => t.IdOrder == idOrder).totalCost  = DataBase.GetCost(idOrder, GetTranslator(idTranslator));
            entity.SaveChanges();
        }
Exemplo n.º 17
0
        public static bool UpdateUser(user userUpdate)
        {
            var  entity = new sovadb001Entities0();
            user us     = entity.users.First(t => t.Id == userUpdate.Id);

            if (us != null)
            {
                us.name  = userUpdate.name;
                us.email = userUpdate.email;
                entity.SaveChanges();
                return(true);
            }

            return(false);
        }
Exemplo n.º 18
0
        public static float GetCost(int idOrder, translator translator)
        {
            var   entity = new sovadb001Entities0();
            var   order = GetOrder(idOrder);
            float cost = 0;
            int   i = 0; float t = 0;

            foreach (var ord in order.documentSpecializations)
            {
                t += (float)translator.prices.FirstOrDefault(r => r.IdSpecialization == ord.IdSpecialization).price1;
                i++;
            }
            cost = t / i;
            return(cost);
        }
Exemplo n.º 19
0
        public static void AddTranslator(int[] idSpec, int idUser)
        {
            var        entity = new sovadb001Entities0();
            translator nt     = new translator();

            nt.countOfComplitedOrders = 0;
            nt.IdUser = idUser;
            entity.translators.Add(nt);
            entity.SaveChanges();
            double[] p = new double[idSpec.Length];
            int      x = 0;

            foreach (int i in idSpec)
            {
                price          pr = GetSpecialization(i).prices.First(t => t.IdTranslator == entity.translators.First(q => q.IdUser == idUser).IdTranslator);
                specialization s  = GetSpecialization(i);
                if (pr != null)
                {
                    p[x] = (double)(pr.price1 / s.complexity);
                }
                else
                {
                    p[x] = 0;
                }
                x++;
            }
            double sum = 0;

            for (int i = 0; i < p.Length; i++)
            {
                sum += p[i];
            }
            sum /= p.Length;
            double sum1 = 0;

            for (int i = 0; i < p.Length; i++)
            {
                if (p[i] != 0)
                {
                    p[i] -= sum;
                    p[i]  = Math.Abs(p[i]);
                    sum1 += p[i];
                }
            }
            entity.translators.First(q => q.IdUser == idUser).reputation = (int)sum1;
            entity.SaveChanges();
        }
Exemplo n.º 20
0
        public static void DeleteApplication(int id)
        {
            var entity = new sovadb001Entities0();

            //auth.AuthHelper.GetUser(HttpContext);
            foreach (var t in entity.documentSpecializations.Where(r => r.IdOrder == id))
            {
                entity.documentSpecializations.Remove(t);
            }
            foreach (var t in entity.documents.Where(r => r.idOrder == id))
            {
                System.IO.File.Delete("C:\\Users\\Олександр\\Documents\\Visual Studio 2012\\Projects\\SovaTranslate_001\\SovaTranslate_001\\Content\\file\\" + t.pathToDoc);
                entity.documents.Remove(t);
            }
            entity.orders.Remove(entity.orders.First(r => r.IdOrder == id));
            entity.SaveChanges();
        }
Exemplo n.º 21
0
        public static bool UpdateUser(user userUpdate, HttpContextBase httpContext)
        {
            var authCookie = httpContext.Request.Cookies["__AUTH"];
            var entity     = new sovadb001Entities0();

            if (authCookie != null)
            {
                user user = entity.users.FirstOrDefault(u => u.cookies == authCookie.Value);

                user.name  = userUpdate.name;
                user.email = userUpdate.email;
                entity.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 22
0
        public ActionResult AddTranslation(int idOrder, HttpPostedFileBase[] UploadedFiles)
        {
            sovadb001Entities0 db = new sovadb001Entities0();

            // order o = db.orders.First(t => t.IdOrder == idOrder);
            foreach (var UpF in UploadedFiles)
            {
                string fileName = System.IO.Path.GetFileName(UpF.FileName);
                UpF.SaveAs(Server.MapPath("~/Content/translate/") + fileName);
                document ndoc = new document();
                ndoc.pathToDoc   = fileName;
                ndoc.isTranslate = true;
                ndoc.idOrder     = idOrder;
                db.documents.Add(ndoc);
            }
            db.orders.First(t => t.IdOrder == idOrder).isDone = true;
            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 23
0
        public ActionResult  GenereteReport()
        {
            sovadb001Entities0 db  = new sovadb001Entities0();
            Report             rep = new Report();

            rep.countadmin = db.users.Where(t => t.roleid == 3).ToArray().Length;

            rep.countoperator = db.users.Where(t => t.roleid == 2).ToArray().Length;

            rep.countmanager = db.users.Where(t => t.roleid == 1).ToArray().Length;

            rep.countuser = db.users.Where(t => t.roleid == 0).ToArray().Length;
            rep.ord       = db.orders.Where(t => t.isDone == true && t.dateOfCompletion.Month > DateTime.Now.Month - 1).ToList();
            double r = 0;

            foreach (var i in rep.ord)
            {
                r += (double)i.totalCost;
            }
            return(View(rep));
        }
Exemplo n.º 24
0
        public static double[,] TextSpecialization(string filename, int LanguageId)
        {
            int      R     = 10;
            Document docum = new Document();

            docum.LoadFromFile(filename, FileFormat.Auto);
            docum.Document.SaveToTxt("C:\\Users\\Олександр\\Documents\\Visual Studio 2012\\Projects\\SovaTranslate_001\\SovaTranslate_001\\Content\\1.txt", System.Text.Encoding.GetEncoding(65001));
            int position          = 0;
            sovadb001Entities0 db = new sovadb001Entities0();


            string[]     lines     = System.IO.File.ReadAllLines("C:\\Users\\Олександр\\Documents\\Visual Studio 2012\\Projects\\SovaTranslate_001\\SovaTranslate_001\\Content\\1.txt");
            List <specw> specwords = new List <specw>();
            int          w         = 0;

            foreach (string line in lines)
            {
                string[] words = line.Split(' ');
                foreach (string word in words)
                {
                    WordsSpecialization d = db.WordsSpecializations.FirstOrDefault(r => r.isWordSpecialization == true && r.languageId == LanguageId && r.word == word);
                    if (d != null)
                    {
                        specw s = new specw(position, d.IdSpecialization, w);
                        w++;
                        specwords.Add(s);
                    }
                    position++;
                }
            }
            //Clasterization
            List <specw> specwords1 = new List <specw>();

            specwords1.AddRange(specwords);

            Random       rand     = new Random();
            List <int[]> clasters = new List <int[]>();



            while (specwords1.Count != 0)
            {
                specw wordC = new specw(specwords1[rand.Next(0, specwords1.Count)].pos, specwords1[rand.Next(0, specwords1.Count)].spec, 0);

                int npos = wordC.pos;

                List <int> claster = new List <int>();
                do
                {
                    npos = wordC.pos;
                    claster.Clear();
                    int x = 0;
                    foreach (var i in specwords)
                    {
                        if (specwords1.Contains(i) && i.spec == wordC.spec && Math.Abs(wordC.pos - i.pos) < R)
                        {
                            claster.Add(x);
                        }
                        x++;
                    }


                    int sum = 0;
                    for (int j = 0; j < claster.Count; j++)
                    {
                        sum += specwords[claster[j]].pos;
                    }
                    sum      /= claster.Count;
                    wordC.pos = sum;
                }while (npos != wordC.pos);
                if (claster != null)
                {
                    clasters.Add(claster.ToArray());
                    int r = 0;
                    foreach (int i in claster)
                    {
                        specwords1.Remove(specwords1.First(g => g.ind == i));
                        r++;
                    }
                }
            }
            //endClast
            // List<int[]> nclasters = new List<int[]>();
            // int t = 0;
            //for(int i =0; i<clasters.Count-t;i++){
            //    bool flag = false;
            //for(int j =0; j<clasters.Count-t;j++){
            //    if (i != j)
            //    {
            //        if (specwords[clasters[i][0]].spec == specwords[clasters[j][0]].spec)
            //        {
            //            flag = true;
            //            List<int> nlist = new List<int>();
            //            nlist.AddRange(clasters[i]);
            //            nlist.AddRange(clasters[j]);

            //            nclasters.Add(nlist.ToArray());
            //        }
            //    }
            //}
            //if (!flag) { nclasters.Add(clasters[i]); }
            //}

            double[,] result = new double[clasters.Count, 2];
            for (int i = 0; i < clasters.Count; i++)
            {
                int min = 999999999;

                int max = 0;
                foreach (var j in clasters[i])
                {
                    if (specwords[j].pos < min)
                    {
                        min = specwords[j].pos;
                    }
                    if (specwords[j].pos > max)
                    {
                        max = specwords[j].pos;
                    }
                }
                result[i, 0] = Math.Abs(max - min);
                result[i, 1] = specwords[(clasters[i])[0]].spec;
            }
            double[,] nresult = new double[result.GetLength(0), 2];
            int t = 0;
            int f = 0;

            for (int i = 0; i < result.GetLength(0) - t; i++)
            {
                bool flag = false;
                if (result[i, 0] != 0)
                {
                    for (int j = i + 1; j < clasters.Count - t; j++)
                    {
                        if (i != j)
                        {
                            if (result[i, 1] == result[j, 1])
                            {
                                flag          = true;
                                nresult[f, 0] = result[i, 0] + result[j, 0];
                                nresult[f, 1] = result[i, 1];
                                result[i, 0] += result[j, 0];
                                result[j, 0]  = 0;
                                f++;
                            }
                        }
                    }
                }
                if (!flag)
                {
                    nresult[f, 0] = result[i, 0];
                    nresult[f, 1] = result[i, 1];
                    f++;
                }
            }
            for (int o = 0; o < result.GetLength(0); o++)
            {
                result[o, 0] = (result[o, 0] * 100) / position;
            }


            return(result);
        }
Exemplo n.º 25
0
        public static List <specialization> GetSpecializations()
        {
            var entity = new sovadb001Entities0();

            return(entity.specializations.ToList());
        }
Exemplo n.º 26
0
        public static order GetOrder(int idOrder)
        {
            var entity = new sovadb001Entities0();

            return(entity.orders.FirstOrDefault(t => t.IdOrder == idOrder));
        }
Exemplo n.º 27
0
        public static translator GetTranslator(int id)
        {
            var entity = new sovadb001Entities0();

            return(entity.translators.First(t => t.IdTranslator == id));
        }
Exemplo n.º 28
0
        public static bool orderIsUser(int idorder, int iduser)
        {
            var entity = new sovadb001Entities0();

            return(entity.orders.First(t => t.IdOrder == idorder).idUser == iduser);
        }
Exemplo n.º 29
0
        public static string GetLanguageName(int id)
        {
            var entity = new sovadb001Entities0();

            return(entity.specializations.First(t => t.isLanguage == true && t.IdSpecialization == id).name);
        }
Exemplo n.º 30
0
        public static List <order> GetUserOrders(user u)
        {
            var entity = new sovadb001Entities0();

            return(entity.orders.Where(f => f.idUser == u.Id).ToList());
        }