示例#1
0
        private void HandleUser()
        {
            using (var db = new MLEEntities())
            {
                var u = new User()
                {
                    Username    = txtUsername.Text,
                    Password    = LoginHelper.SHA256(txtPassword.Text),
                    FirstName   = txtFirstName.Text,
                    LastName    = txtLastName.Text,
                    E_mail      = txtMail.Text,
                    DateCreated = DateTime.Now,
                    IsActive    = true
                };

                db.User.Add(u);
                db.SaveChanges();

                // It's always Client
                // Administator can change it in Admin
                var ur = new UserRole()
                {
                    UserId = u.Id,
                    RoleId = 2
                };

                db.UserRole.Add(ur);
                db.SaveChanges();
            }

            var subject = "MLE registracija";
            var body    = "<h3>Da bi se prijavili u sustav, administrator mora pregledati Vašu prijavu!</h3>";

            LoginHelper.SendMail(txtMail.Text, subject, body);
        }
示例#2
0
        private void Save()
        {
            using (var db = new MLEEntities())
            {
                var _user = new User()
                {
                    FirstName = txtName.Text,
                    LastName = txtSurname.Text,
                    E_mail = txtEmail.Text,
                    Username = txtUsername.Text,
                    Password = LoginHelper.SHA256(txtPassword.Text),
                    Description = txtDescription.Text,
                    IsActive = cbIsActive.Checked,
                    DateCreated = DateTime.Now
                };
                db.User.Attach(_user);
                db.User.Add(_user);
                db.SaveChanges();

                var users = db.User.OrderByDescending(u => u.Id).Take(1).ToList();
                var _userRole = new UserRole()
                {
                    UserId = users[0].Id,
                    RoleId = int.Parse(roleList.SelectedValue)
                };
                db.UserRole.Attach(_userRole);
                db.UserRole.Add(_userRole);
                db.SaveChanges();
            }
        }
示例#3
0
        private void Update()
        {
            using (var db = new MLEEntities())
            {
                var _dbUser = db.User.Where(u => u.Id == userId).FirstOrDefault();
                if (_dbUser != null)
                {
                    db.User.Attach(_dbUser);
                    _dbUser.FirstName = txtName.Text;
                    _dbUser.LastName = txtSurname.Text;
                    _dbUser.E_mail = txtEmail.Text;
                    _dbUser.Username = txtUsername.Text;
                    if (txtPassword.Text != "")
                        _dbUser.Password = LoginHelper.SHA256(txtPassword.Text);
                    _dbUser.Description = txtDescription.Text;
                    _dbUser.IsActive = cbIsActive.Checked;
                    db.SaveChanges();
                }

                var _userRole = db.UserRole.Where(u => u.UserId == _dbUser.Id).FirstOrDefault();
                if (_userRole != null)
                {
                    db.UserRole.Attach(_userRole);
                    _userRole.RoleId = int.Parse(roleList.SelectedValue);
                    _userRole.UserId = _dbUser.Id;
                    db.SaveChanges();
                }
            }
        }
示例#4
0
        private void Delete()
        {
            categoryId = int.Parse(Request.QueryString["id"]);

            using (var db = new MLEEntities())
            {
                Category _dbCategory = db.Category.Where(u => u.Id == categoryId).FirstOrDefault();

                List <Subcategory> subcategories = db.Subcategory.Where(c => c.CategoryId == categoryId).ToList();

                if (subcategories.Count != 0)
                {
                    db.Subcategory.RemoveRange(subcategories);
                    db.SaveChanges();
                }


                if (!db.Example.Any(e => e.CategoryId == categoryId))
                {
                    db.Category.Attach(_dbCategory);
                    db.Category.Remove(_dbCategory);
                }

                db.SaveChanges();
            }
        }
        protected void btnSendMail_Click(object sender, EventArgs e)
        {
            using (var db = new MLEEntities())
            {
                var u = db.User.FirstOrDefault(x => x.E_mail == txtForgotMail.Text);
                if (u != null)
                {
                    var f = db.ForgotPassword.FirstOrDefault(x => x.UserId == u.Id);
                    if (f != null)
                    {
                        f.IsValid = false;
                        db.SaveChanges();
                    }

                    var fp = new DB.ForgotPassword()
                    {
                        UserId        = u.Id,
                        InsertedEmail = u.E_mail,
                        DateTime      = DateTime.Now,
                        WrongEmail    = false,
                        GeneratedKey  = LoginHelper.SHA256(u.Id + u.E_mail + DateTime.Now.Ticks),
                        ValidUntil    = DateTime.Now.AddDays(1),
                        IsValid       = true,
                        IsUsed        = false
                    };

                    db.ForgotPassword.Attach(fp);
                    db.ForgotPassword.Add(fp);
                    db.SaveChanges();

                    var subject = "MLE zaboravljena lozinka";
                    var body    = "Da biste promijenili lozinku, potrebno je kliknuti na sljedeću poveznicu: <a href='http://mle.s15.novenaweb.info/Client/ChangePassword.aspx?key=" + fp.GeneratedKey + "'>http://mle.s15.novenaweb.info/Client/ChangePassword.aspx?key=" + fp.GeneratedKey + "</a>.<br>Poveznica neće biti valjana nakon 24 sata.";
                    LoginHelper.SendMail(u.E_mail, subject, body);
                }
                else
                {
                    var fp = new DB.ForgotPassword()
                    {
                        InsertedEmail = txtForgotMail.Text,
                        DateTime      = DateTime.Now,
                        Description   = "Inserted mail is not existing in database. Key not generated!",
                        WrongEmail    = true,
                        IsValid       = false,
                        IsUsed        = false
                    };

                    db.ForgotPassword.Attach(fp);
                    db.ForgotPassword.Add(fp);
                    db.SaveChanges();
                }
            }
            MailSent           = true;
            txtForgotMail.Text = String.Empty;
        }
示例#6
0
        private void Delete()
        {
            if (Request.QueryString["id"] != null)
            {
                var id = Request.QueryString["id"].ToString();
                projectId = int.Parse(id);
                using (var db = new MLEEntities())
                {
                    var examples = db.Example.Where(x => x.ProjectId == projectId).ToList();
                    foreach (var item in examples)
                    {
                        var marked = db.Marked.Where(x => x.ExampleId == item.Id).ToList();
                        foreach (var i in marked)
                        {
                            db.Marked.Attach(i);
                            db.Marked.Remove(i);
                            db.SaveChanges();
                        }

                        var ec = db.ExampleCategory.Where(x => x.ExampleId == item.Id).ToList();
                        foreach (var i in ec)
                        {
                            db.ExampleCategory.Attach(i);
                            db.ExampleCategory.Remove(i);
                            db.SaveChanges();
                        }

                        db.Example.Attach(item);
                        db.Example.Remove(item);
                        db.SaveChanges();
                    }

                    var userProject = db.UserProject.Where(x => x.ProjectId == projectId).ToList();
                    foreach (var item in userProject)
                    {
                        db.UserProject.Attach(item);
                        db.UserProject.Remove(item);
                        db.SaveChanges();
                    }

                    Project _dbProject = db.Project.Where(u => u.Id == projectId).FirstOrDefault();
                    db.Project.Attach(_dbProject);
                    db.Project.Remove(_dbProject);
                    db.SaveChanges();
                }

                Response.Redirect("Projects.aspx");
            }
        }
示例#7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                exampleId = int.Parse(Request.QueryString["id"].ToString());

                using (var db = new MLEEntities())
                {
                    if (exampleId != 0)
                    {
                        var _ = db.Example.FirstOrDefault(x => x.Id == exampleId);
                        if (_ != null)
                        {
                            _.Description = txtDescription.Text;
                            _.Content     = txtContent.Text;
                            _.ProjectId   = int.Parse(projectList.SelectedValue);
                            _.StatusId    = int.Parse(statusList.SelectedValue);
                            _.CategoryId  = int.Parse(categoryList.SelectedValue);
                            _.TypeId      = int.Parse(ddlType.SelectedValue);

                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        Example _example = new Example()
                        {
                            Content     = txtContent.Text,
                            Description = txtDescription.Text,
                            DateCreated = DateTime.Now,
                            TimeSpent   = TimeSpan.Zero,
                            ProjectId   = int.Parse(projectList.SelectedValue),
                            StatusId    = int.Parse(statusList.SelectedValue),
                            CategoryId  = int.Parse(categoryList.SelectedValue),
                            TypeId      = int.Parse(ddlType.SelectedValue),
                            FileName    = ""
                        };

                        db.Example.Attach(_example);
                        db.Example.Add(_example);

                        db.SaveChanges();
                    }

                    Response.Redirect("Examples.aspx");
                }
            }
        }
示例#8
0
        private void CreateNewSubcategory(MLEEntities db, FileHelper.Subcategory subcategory, int?categoryID, int counter)
        {
            var s     = new Subcategory();
            var name  = "";
            var color = "";

            if (subcategory != null && counter != 0)
            {
                name  = subcategory.Name;
                color = subcategory.Color;
                var rnd = new Random();
                if (color == null)
                {
                    if (counter > FileHelper.Default_colors.Count - 1)
                    {
                        color = HexConverter(Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)));
                    }
                    else
                    {
                        color = FileHelper.Default_colors[counter];
                    }
                }
            }
            s.Name        = name;
            s.Color       = color;
            s.CategoryId  = categoryID;
            s.Description = "Automatic upload (ZIP)";
            s.isActive    = true;
            db.Subcategory.Add(s);
            db.SaveChanges();
        }
示例#9
0
        private void Save()
        {
            using (var db = new MLEEntities())
            {
                DateTime.TryParse(txtStartDate.Text, out DateTime start_date);

                DateTime.TryParse(txtEndDate.Text, out DateTime end_date);

                Project _project = new Project()
                {
                    Name        = txtName.Text,
                    Description = txtDescription.Text,
                    DateCreated = DateTime.Now,
                    TimeSpent   = TimeSpan.Zero,
                    Start_Date  = start_date,
                    End_Date    = end_date.Year == 0001 ? DateTime.Now : end_date,
                    StatusId    = int.Parse(ddlStatus.SelectedValue)
                };

                db.Project.Attach(_project);
                db.Project.Add(_project);

                db.SaveChanges();
            }
        }
示例#10
0
        private void ImportData()
        {
            var d     = new DirectoryInfo(Server.MapPath("/DataImport"));
            var files = d.GetFiles("*.txt");

            foreach (var file in files)
            {
                var path = Server.MapPath("/DataImport/" + file.Name);
                if (File.Exists(path))
                {
                    var reader = File.OpenText(path);
                    var text   = reader.ReadToEnd();
                    if (text != null)
                    {
                        using (var db = new MLEEntities())
                        {
                            var fileIsAlreadyInDB = db.Example.Where(x => x.FileName == file.Name || x.Content == text).FirstOrDefault() != null ? true : false;
                            if (!fileIsAlreadyInDB)
                            {
                                var ls       = text.Split('.').ToList();
                                var new_text = "";
                                for (int i = 1; i <= ls.Count - 1; i++)
                                {
                                    new_text += "<span ID='" + i + "'>" + ls[i] + ".</span>";
                                }

                                var example = new Example
                                {
                                    FileName    = file.Name,
                                    Content     = new_text,
                                    Description = "Uploaded data to Database",
                                    DateCreated = DateTime.Now,
                                    StatusId    = 3 // U tijeku
                                };

                                db.Example.Add(example);
                                db.SaveChanges();

                                UploadSuccessful++;
                            }
                            else
                            {
                                UploadExists++;
                            }
                        }
                    }
                    else
                    {
                        UploadError++;
                    }
                }
                else
                {
                    UploadError++;
                }
            }
        }
示例#11
0
        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            using (var db = new MLEEntities())
            {
                var u = db.User.FirstOrDefault(x => x.Id == fp.UserId);
                if (u != null)
                {
                    u.Password = LoginHelper.SHA256(txtChangePassword.Text);
                    db.SaveChanges();

                    db.ForgotPassword.Attach(fp);
                    fp.IsUsed  = true;
                    fp.IsValid = false;
                    db.SaveChanges();
                }
            }

            RedirectToLogin();
        }
示例#12
0
 private void Delete()
 {
     subcategoryId = int.Parse(Request.QueryString["id"]);
     using (var db = new MLEEntities())
     {
         var sc = db.Subcategory.Where(u => u.Id == subcategoryId).FirstOrDefault();
         db.Subcategory.Remove(sc);
         db.SaveChanges();
     }
 }
示例#13
0
        private void CreateNewCategory(MLEEntities db, string category_name, ref int?CategoryID)
        {
            var c = new DB.Category();

            c.isActive    = true;
            c.Name        = category_name;
            c.Description = "Automatic upload (ZIP)";
            db.Category.Add(c);
            db.SaveChanges();

            CategoryID = c.Id;
        }
示例#14
0
        public static void Finish(string ExampleId)
        {
            var Int_ExampleId = Convert.ToInt32(ExampleId);

            using (var db = new MLEEntities())
            {
                var e = db.Example.FirstOrDefault(x => x.Id == Int_ExampleId);
                if (e != null)
                {
                    e.StatusId = 2;
                    db.SaveChanges();
                }
            }
        }
示例#15
0
        protected void btnAddUser_Click(object sender, EventArgs e)
        {
            projectId = int.Parse(Request.QueryString["id"].ToString());
            var userId = int.Parse(ddlUser.SelectedValue);

            using (var db = new MLEEntities())
            {
                var up = new UserProject();
                up.ProjectId = projectId;
                up.UserId    = userId;
                db.UserProject.Add(up);
                db.SaveChanges();
            }
        }
示例#16
0
        public static void SaveEntity(string ExampleId, string Content)
        {
            var Int_ExampleId = Convert.ToInt32(ExampleId);

            using (var db = new MLEEntities())
            {
                var e = db.Example.FirstOrDefault(x => x.Id == Int_ExampleId);
                if (e != null)
                {
                    e.Content = Content;
                    db.SaveChanges();
                }
            }
        }
示例#17
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] == null)
            {
                return;
            }

            var str = Request.QueryString["id"].ToString();

            typeId = int.Parse(str);

            using (var db = new MLEEntities())
            {
                if (typeId != 0)
                {
                    var t = db.Type.Where(x => x.Id == typeId).FirstOrDefault();
                    if (t != null)
                    {
                        t.Name   = txtName.Text;
                        t.Active = cbActive.Checked;
                        db.SaveChanges();
                    }
                }
                else
                {
                    var t = new MLE.DB.Type()
                    {
                        Name   = txtName.Text,
                        Active = cbActive.Checked
                    };

                    db.Type.Add(t);
                    db.SaveChanges();
                }
                PopulateRepeater(false);
            }
        }
示例#18
0
        protected void btnRemoveUser_Click(object sender, EventArgs e)
        {
            projectId = int.Parse(Request.QueryString["id"].ToString());
            var userId = int.Parse(ddlUser.SelectedValue);

            using (var db = new MLEEntities())
            {
                var up = db.UserProject.FirstOrDefault(x => x.ProjectId == projectId && x.UserId == userId);
                if (up != null)
                {
                    db.UserProject.Remove(up);
                    db.SaveChanges();
                }
            }
        }
示例#19
0
        private void Delete()
        {
            using (var db = new MLEEntities())
            {
                var _dbUser = db.User.Where(u => u.Id == userId).FirstOrDefault();
                var userExamples = db.UserProject.Where(ue => ue.UserId == _dbUser.Id).ToList();

                if (userExamples.Count != 0)
                {
                    db.UserProject.RemoveRange(userExamples);
                    db.SaveChanges();
                }

                var _userRole = db.UserRole.Where(ur => ur.UserId == _dbUser.Id).FirstOrDefault();

                db.UserRole.Attach(_userRole);
                db.UserRole.Remove(_userRole);

                db.User.Attach(_dbUser);
                db.User.Remove(_dbUser);

                db.SaveChanges();
            }
        }
示例#20
0
        protected void btnRemoveType_Click(object sender, EventArgs e)
        {
            projectId = int.Parse(Request.QueryString["id"].ToString());
            var typeId = int.Parse(ddlType.SelectedValue);

            using (var db = new MLEEntities())
            {
                var t = db.Example.Where(x => x.ProjectId == projectId).ToList();
                foreach (var item in t)
                {
                    db.Example.Attach(item);
                    item.TypeId = null;
                    db.SaveChanges();
                }
            }
        }
示例#21
0
        public static void RemoveMarked(string EntityId, string SentenceId, string TextId)
        {
            var Int_EntityId   = Convert.ToInt32(EntityId);
            var Int_SentenceId = Convert.ToInt32(SentenceId);
            var Int_ExampleId  = Convert.ToInt32(TextId);

            using (var db = new MLEEntities())
            {
                var m = db.Marked.FirstOrDefault(x => x.EntityId == Int_EntityId && x.SentenceId == Int_SentenceId && x.ExampleId == Int_ExampleId);
                if (m != null)
                {
                    db.Marked.Remove(m);
                    db.SaveChanges();
                }
            }
        }
示例#22
0
        private void Save()
        {
            using (var db = new MLEEntities())
            {
                Category _category = new Category()
                {
                    Name        = txtCategoryName.Text,
                    Description = txtDescription.Text,
                    isActive    = cbIsActive.Checked,
                };

                db.Category.Attach(_category);
                db.Category.Add(_category);

                db.SaveChanges();
            }
        }
示例#23
0
        private void Update()
        {
            using (var db = new MLEEntities())
            {
                var sc = db.Subcategory.Where(u => u.Id == subcategoryId).FirstOrDefault();

                if (sc != null)
                {
                    db.Subcategory.Attach(sc);
                    sc.Name        = txtSubcategoryName.Text;
                    sc.Description = txtDescription.Text;
                    sc.isActive    = cbIsActive.Checked;
                    sc.Color       = txtColor.Text;
                    db.SaveChanges();
                }
            }
        }
示例#24
0
        public static bool ChangeStatus(string ExampleId, string StatusId)
        {
            var Int_ExampleId = Convert.ToInt32(ExampleId);
            var Int_StatusId  = Convert.ToInt32(StatusId);

            using (var db = new MLEEntities())
            {
                var e = db.Example.FirstOrDefault(x => x.Id == Int_ExampleId);
                if (e != null)
                {
                    e.StatusId = Int_StatusId;
                    db.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
示例#25
0
        private void Save()
        {
            using (var db = new MLEEntities())
            {
                var sc = new Subcategory()
                {
                    Name        = txtSubcategoryName.Text,
                    Description = txtDescription.Text,
                    isActive    = cbIsActive.Checked,
                    Color       = txtColor.Text,
                    CategoryId  = CId
                };

                db.Subcategory.Attach(sc);
                db.Subcategory.Add(sc);
                db.SaveChanges();
            }
        }
示例#26
0
        private void Update()
        {
            using (var db = new MLEEntities())
            {
                Category _dbCategory = db.Category.Where(u => u.Id == categoryId).FirstOrDefault();

                if (_dbCategory != null)
                {
                    db.Category.Attach(_dbCategory);

                    _dbCategory.Name        = txtCategoryName.Text;
                    _dbCategory.Description = txtDescription.Text;
                    _dbCategory.isActive    = cbIsActive.Checked;

                    db.SaveChanges();
                }
            }
        }
示例#27
0
        public static bool Save(string ExampleId, string SubcategoryId, string SentenceId, string EntityId)
        {
            var int_ExampleId     = Convert.ToInt32(ExampleId);
            var int_SubcategoryId = Convert.ToInt32(SubcategoryId);

            using (var db = new MLEEntities())
            {
                var Marked = new Marked()
                {
                    ExampleId     = int_ExampleId,
                    SubcategoryId = int_SubcategoryId,
                };

                db.Marked.Add(Marked);
                db.SaveChanges();
                return(true);
            }
        }
示例#28
0
        private void Update()
        {
            using (var db = new MLEEntities())
            {
                Project _dbProject = db.Project.Where(u => u.Id == projectId).FirstOrDefault();

                if (_dbProject != null)
                {
                    db.Project.Attach(_dbProject);

                    _dbProject.Name        = txtName.Text;
                    _dbProject.Description = txtDescription.Text;
                    //_dbProject.DateCreated = DateTime.ParseExact(txtDateCreated.Text, "dd/MM/yyyy", null);
                    _dbProject.TimeSpent = TimeSpan.Zero;
                    //_dbProject.Start_Date = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy", null);
                    //_dbProject.End_Date = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy", null);
                    _dbProject.StatusId = int.Parse(ddlStatus.SelectedValue);

                    db.SaveChanges();
                }
            }
        }
示例#29
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] == null)
            {
                return;
            }

            var str = Request.QueryString["id"].ToString();

            typeId = int.Parse(str);

            using (var db = new MLEEntities())
            {
                var t = db.Type.Where(x => x.Id == typeId).FirstOrDefault();
                if (t != null)
                {
                    db.Type.Remove(t);
                    db.SaveChanges();

                    PopulateRepeater(false);
                    Response.Redirect("Type.aspx");
                }
            }
        }
示例#30
0
        public static bool MarkEntity(string EntityId, string ExampleId, string SentenceId, string SubcategoryId, string InputText, bool isChecked)
        {
            var Int_EntityId      = Convert.ToInt32(EntityId);
            var Int_ExampleId     = Convert.ToInt32(ExampleId);
            var Int_SentenceId    = Convert.ToInt32(SentenceId);
            var Int_SubcategoryId = Convert.ToInt32(SubcategoryId);

            var user = LoginHelper.GetUserId();

            if (user == 0)
            {
                return(false);
            }

            using (var db = new MLEEntities())
            {
                var catId           = db.Subcategory.FirstOrDefault(x => x.Id == Int_SubcategoryId).CategoryId;
                var ExampleCategory = db.ExampleCategory.FirstOrDefault(x => x.ExampleId == Int_ExampleId && x.CategoryId == catId);
                if (ExampleCategory != null)
                {
                    var ml = db.Marked.Include(x => x.Example.ExampleCategory).Where(x => x.ExampleId == Int_ExampleId /*&& x.SubcategoryId == Int_SubcategoryId*/ && x.EntityId == null && x.SentenceId == null).ToList();
                    if (ml.Count > 0)
                    {
                        var subs = db.Subcategory.Where(x => x.CategoryId == catId).Select(x => x.Id).ToList();
                        var _m   = ml.Where(x => subs.Contains(x.SubcategoryId.Value)).ToList();
                        if (_m.Count > 0)
                        {
                            //var _ = ml.FirstOrDefault(x => x.SubcategoryId == Int_SubcategoryId);
                            var m      = _m.FirstOrDefault();
                            var typeId = m.Example.ExampleCategory.FirstOrDefault(x => x.CategoryId == catId).TypeId;
                            var type   = db.Type.FirstOrDefault(x => x.Id == typeId);
                            if (type.HTML_name == "radio")
                            {
                                m.SubcategoryId = Int_SubcategoryId;
                                db.SaveChanges();
                            }
                            else if (type.HTML_name == "checkbox")
                            {
                                if (isChecked)
                                {
                                    var _ = new Marked()
                                    {
                                        EntityId      = null,
                                        ExampleId     = Int_ExampleId,
                                        SentenceId    = null,
                                        SubcategoryId = Int_SubcategoryId,
                                        UserId        = user,
                                        Text          = InputText
                                    };
                                    db.Marked.Add(_);
                                    db.SaveChanges();
                                }
                                else
                                {
                                    m = _m.FirstOrDefault(x => x.SubcategoryId == Int_SubcategoryId);
                                    db.Marked.Remove(m);
                                    db.SaveChanges();
                                }
                            }
                            else if (type.HTML_name == "text")
                            {
                                m.Text = InputText;
                                db.SaveChanges();
                            }
                        }
                        else
                        {
                            var _ = new Marked()
                            {
                                EntityId      = null,
                                ExampleId     = Int_ExampleId,
                                SentenceId    = null,
                                SubcategoryId = Int_SubcategoryId != 0 ? Int_SubcategoryId : (int?)null,
                                UserId        = user,
                                Text          = InputText
                            };
                            db.Marked.Add(_);
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        var _ = new Marked()
                        {
                            EntityId      = null,
                            ExampleId     = Int_ExampleId,
                            SentenceId    = null,
                            SubcategoryId = Int_SubcategoryId != 0 ? Int_SubcategoryId : (int?)null,
                            UserId        = user,
                            Text          = InputText
                        };
                        db.Marked.Add(_);
                        db.SaveChanges();
                    }
                    return(false);
                }
                else
                {
                    var ml   = db.Marked.Include(x => x.Example.Type).Where(x => x.EntityId == Int_EntityId && x.ExampleId == Int_ExampleId && x.SentenceId == Int_SentenceId && x.UserId == user).ToList();
                    var ml_U = db.Marked.Include(x => x.Example.Type).FirstOrDefault(x => x.EntityId == Int_EntityId && x.ExampleId == Int_ExampleId && x.SentenceId == Int_SentenceId && x.UserId == null);
                    if (ml.Count > 0)
                    {
                        var m    = ml.FirstOrDefault();
                        var type = m.Example.Type;
                        if (type.HTML_name == "radio")
                        {
                            if (m.SubcategoryId == Int_SubcategoryId)
                            {
                                // provjera ako je automatski unos
                                if (ml_U == null)
                                {
                                    db.Marked.Remove(m);
                                }
                                else
                                {
                                    m.SubcategoryId = null;
                                }
                            }
                            else
                            {
                                m.SubcategoryId = Int_SubcategoryId;
                            }
                            db.SaveChanges();
                        }
                        else if (type.HTML_name == "checkbox")
                        {
                            if (isChecked)
                            {
                                var _ = new Marked()
                                {
                                    EntityId      = Int_EntityId,
                                    ExampleId     = Int_ExampleId,
                                    SentenceId    = Int_SentenceId,
                                    SubcategoryId = Int_SubcategoryId,
                                    UserId        = user,
                                    Text          = InputText
                                };
                                db.Marked.Add(_);
                                db.SaveChanges();
                            }
                            else
                            {
                                m = ml.FirstOrDefault(x => x.SubcategoryId == Int_SubcategoryId);
                                db.Marked.Remove(m);
                                db.SaveChanges();
                            }
                        }
                        else if (type.HTML_name == "text")
                        {
                            m.Text = InputText;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        int?subcategory = Int_SubcategoryId;
                        if (ml_U != null)
                        {
                            subcategory = null;
                        }

                        var _ = new Marked()
                        {
                            EntityId      = Int_EntityId,
                            ExampleId     = Int_ExampleId,
                            SentenceId    = Int_SentenceId,
                            SubcategoryId = subcategory != 0 ? subcategory : null,
                            UserId        = user,
                            Text          = InputText
                        };
                        db.Marked.Add(_);
                        db.SaveChanges();
                    }
                    return(true);
                }
            }
        }