Esempio n. 1
0
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //connect
            try
            {
                using (DefaultConnection conn = new DefaultConnection())
                {
                    //get the selected DepartmentID
                    Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[e.RowIndex].Values["DepartmentID"]);

                    var d = (from dep in conn.Departments
                             where dep.DepartmentID == DepartmentID
                             select dep).FirstOrDefault();

                    //process the delete
                    conn.Departments.Remove(d);
                    conn.SaveChanges();

                    //update the grid
                    GetDepartments();
                }
            }
            catch
            {
                Response.Redirect("error.aspx");
            }
        }
Esempio n. 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL Server
            try
            {
                using (DefaultConnection db = new DefaultConnection())
                {

                    //use the Student model to save the new record
                    Student s = new Student();
                    Int32 StudentID = 0;

                    //check the querystring for an id so we can determine add / update
                    if (Request.QueryString["StudentID"] != null)
                    {
                        //get the id from the url
                        StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                        //get the current student from EF
                        s = (from objS in db.Students
                             where objS.StudentID == StudentID
                             select objS).FirstOrDefault();
                    }

                    s.LastName = txtLastName.Text;
                    s.FirstMidName = txtFirstMidName.Text;
                    s.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text);

                    //call add only if we have no student ID
                    if (StudentID == 0)
                    {
                        db.Students.Add(s);
                    }

                    //run the update or insert
                    db.SaveChanges();

                    //redirect to the updated students page
                    Response.Redirect("students.aspx");
                }
            }
            catch
            {
                Response.Redirect("error.aspx");
            }
        }
Esempio n. 3
0
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify the department id to be deleted from the row the user selected
            Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[e.RowIndex].Values["DepartmentID"]);

            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Department dep = (from d in db.Departments
                                  where d.DepartmentID == DepartmentID
                                  select d).FirstOrDefault();
                //delete
                db.Departments.Remove(dep);
                db.SaveChanges();

                //refresh the grid
                GetDepartments();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create a new course and fill the properties
                Course objC = new Course();

                objC.Title = txtTitle.Text;
                objC.Credits = Convert.ToInt32(txtCredits.Text);
                objC.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue);

                //save
                db.Courses.Add(objC);
                db.SaveChanges();

                //redirect
                Response.Redirect("courses.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect to server
            using (DefaultConnection db = new DefaultConnection())
            {
                //Create a new student_details in memory
                Student stud = new Student();

                Int32 StudentID = 0;

                //check for a url
                if (!String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    //get the id from the url
                    StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                    //look up the student
                    stud = (from s in db.Students
                            where s.StudentID == StudentID
                            select s).FirstOrDefault();
                }

                //Fill the properties of the new student
                stud.LastName = txtLastName.Text;
                stud.FirstMidName = txtFirstMidName.Text;
                stud.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text);

                //add if we have no id in the url
                if (StudentID == 0)
                {
                    db.Students.Add(stud);
                }

                //save the new student
                db.SaveChanges();

                //redirect to the students list page
                Response.Redirect("students.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect to server
            using (DefaultConnection db = new DefaultConnection())
            {
                //Create a new department_details in memory
                Department dep = new Department();

                Int32 DepartmentID = 0;

                //check for a url
                if (!String.IsNullOrEmpty(Request.QueryString["DepartmentID"]))
                {
                    //get the id from the url
                    DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                    //look up the department
                    dep = (from d in db.Departments
                           where d.DepartmentID == DepartmentID
                           select d).FirstOrDefault();
                }

                //Fill the properties of the new department
                dep.Name = txtName.Text;
                dep.Budget = Convert.ToDecimal(txtBudget.Text);

                //add if we have no id in the url
                if (DepartmentID == 0)
                {
                    db.Departments.Add(dep);
                }

                //save the new department
                db.SaveChanges();

                //redirect to the departments list page
                Response.Redirect("departments.aspx");
            }
        }
Esempio n. 7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            try
            {
                using (DefaultConnection conn = new DefaultConnection())
                {
                    //instantiate a new deparment object in memory
                    Department d = new Department();

                    //decide if updating or adding, then save
                    if (Request.QueryString.Count > 0)
                    {
                        Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                        d = (from dep in conn.Departments
                             where dep.DepartmentID == DepartmentID
                             select dep).FirstOrDefault();
                    }

                    //fill the properties of our object from the form inputs
                    d.Name = txtName.Text;
                    d.Budget = Convert.ToDecimal(txtBudget.Text);

                    if (Request.QueryString.Count == 0)
                    {
                        conn.Departments.Add(d);
                    }
                    conn.SaveChanges();

                    //redirect to updated departments page
                    Response.Redirect("departments.aspx");
                }
            }
            catch
            {
                Response.Redirect("error.aspx");
            }
        }
Esempio n. 8
0
        // protected void grdStudents_PageIndexChanging(object sender, GridViewPageEventArgs e)
        // {
        //set the NewPageIndex and repopulate the grid
        //grdStudents.PageIndex = e.NewPageIndex;
        // GetStudents();
        // }
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //Store which row was clicked
            Int32 selectedRow = e.RowIndex;

            //get the selected StudentID using the grid's Data collection
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[selectedRow].Values["StudentID"]);

            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Student stud = (from s in db.Students
                                where s.StudentID == StudentID
                                select s).FirstOrDefault();
                //delete
                db.Students.Remove(stud);
                db.SaveChanges();

                //refresh the grid
                GetStudents();
            }
        }
Esempio n. 9
0
        protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 CourseID = Convert.ToInt32(grdCourses.DataKeys[e.RowIndex].Values["CourseID"].ToString());

            try
            {
                using (DefaultConnection db = new DefaultConnection())
                {
                    Course objC = (from c in db.Courses
                                   where c.CourseID == CourseID
                                   select c).FirstOrDefault();

                    db.Courses.Remove(objC);
                    db.SaveChanges();
                }

                GetCourses();
            }
            catch
            {
                Response.Redirect("error.aspx");
            }
        }
Esempio n. 10
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            Department department = new Department();

            using (DefaultConnection db = new DefaultConnection())
            {
                int departmentId = 0;
                if (Request.QueryString.Count > 0)
                {
                    departmentId = Convert.ToInt32(Request.QueryString["DepartmentID"]);
                    department   = (from depart in db.Departments
                                    where depart.DepartmentID == departmentId
                                    select depart).FirstOrDefault();
                }
                department.Name   = NameTextBox.Text;
                department.Budget = Convert.ToDecimal(BudgetTextBox.Text.ToString());
                if (departmentId == 0)
                {
                    db.Departments.Add(department);
                }
                db.SaveChanges();
                Response.Redirect("~/Departments.aspx");
            }
        }
Esempio n. 11
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //use EF to connect to the server
            using (DefaultConnection db = new DefaultConnection())
            {
                //use the student model to save a new record
                Student newStudent = new Student();

                int StudentID = 0;

                if (Request.QueryString.Count > 0)
                {
                    //get the id from the URL
                    StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                    //get the current student from EF DB
                    newStudent = (from student in db.Students
                                  where student.StudentID == StudentID
                                  select student).FirstOrDefault();
                }

                newStudent.LastName       = LastNameTextBox.Text;
                newStudent.FirstMidName   = FirstNameTextBox.Text;
                newStudent.EnrollmentDate = Convert.ToDateTime(EnrollmentDateTextBox.Text);

                if (StudentID == 0)
                {
                    db.Students.Add(newStudent);
                }

                //run an insert command
                db.SaveChanges();
                //redirect back to the students page
                Response.Redirect("~/Students.aspx");
            }
        }
Esempio n. 12
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // Use EF to connect to the server
            using (DefaultConnection db = new DefaultConnection())
            {
                // use the Student model to create a new student object and
                // save a new record
                Student newStudent = new Student();

                // add form data to the new student record
                newStudent.LastName       = LastNameTextBox.Text;
                newStudent.FirstMidName   = FirstNameTextBox.Text;
                newStudent.EnrollmentDate = Convert.ToDateTime(EnrollmentDateTextBox.Text);

                // use LINQ to ADO.NET to add / insert new student into the database
                db.Students.Add(newStudent);

                // save our changes
                db.SaveChanges();

                // Redirect back to the updated students page
                Response.Redirect("~/Students.aspx");
            }
        }
Esempio n. 13
0
        protected void DepartmentsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // store which row was clicked
            int selectedRow = e.RowIndex;

            // get the selected DepartmentID using the Grid's DataKey Collection
            int DepartmentID = Convert.ToInt32(DepartmentsGridView.DataKeys[selectedRow].Values["DepartmentID"]);

            // use EF to find the selected Department from DB and remove it
            using (DefaultConnection db = new DefaultConnection())
            {
                Department deletedDepartment = (from DepartmentRecords in db.Departments
                                                where DepartmentRecords.DepartmentID == DepartmentID
                                                select DepartmentRecords).FirstOrDefault();

                // perform the removal in the DB
                db.Departments.Remove(deletedDepartment);
                db.SaveChanges();


                // refresh the grid
                this.GetDepartments();
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // connect to EF DB
            using (DefaultConnection db = new DefaultConnection())
            {
                // use the student model to save a new record
                Department newDepartment = new Department();

                int DepartmentID = 0;

                //IF adding a new student, run this, else skip it
                if (Request.QueryString.Count > 0) //Our URL HAS a student id
                {
                    DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                    newDepartment = (from department in db.Departments
                                     where department.DepartmentID == DepartmentID
                                     select department).FirstOrDefault();
                }

                newDepartment.Name   = NameTextBox.Text;
                newDepartment.Budget = Convert.ToDecimal(BudgetTextBox.Text);

                //Only add if new student
                if (DepartmentID == 0)
                {
                    db.Departments.Add(newDepartment);
                }

                // run insert in DB
                db.SaveChanges();

                // redirect to the updated students page
                Response.Redirect("~/Departments.aspx");
            }
        }
        public ActionResult VersionEdit([Bind(Include = "ID,Title,Category,Slug,Date,Body,Body2,UserID")] EP_POSTS EP_POST, int?return_id)
        {
            if (ModelState.IsValid)
            {
                EP_POSTS ep      = db.EP_POST.Find(return_id);
                string   guidval = ep.GUID;
                EP_POST.GUID   = guidval;
                EP_POST.Ref    = guidval;
                EP_POST.UserID = User.Identity.GetUserId();
                EP_POST.Date   = DateTime.Now;
                EP_POST.Type   = "Post";

                db.EP_POST.Add(EP_POST);
                db.SaveChanges();

                return(RedirectToAction("Index", "Archive"));
            }
            return(View(EP_POST));
        }
Esempio n. 16
0
        public IHttpActionResult SetMood(string id)
        {
            var       mood = _db.Mood.ToList().Where(x => x.UserId == id.Split('_')[0]);
            MoodModel mm   = new MoodModel();
            int       type = Convert.ToInt32(id.Split('_')[1]);

            var moodModels = mood as MoodModel[] ?? mood.ToArray();

            if (moodModels.Any())
            {
                if (mm.Date == DateTime.Now.ToString())
                {
                    mm                  = moodModels.First();
                    mm.Date             = DateTime.Now.ToString();
                    mm.Type             = type;
                    _db.Entry(mm).State = System.Data.Entity.EntityState.Modified;
                    _db.SaveChanges();
                }
                else
                {
                    mm.Id     = Guid.NewGuid().ToString();
                    mm.UserId = id;
                    mm.Date   = DateTime.Now.ToString();
                    mm.Type   = type;
                    _db.Mood.Add(mm);
                    _db.SaveChanges();
                }
            }
            else
            {
                mm.Id     = Guid.NewGuid().ToString();
                mm.UserId = id;
                mm.Date   = DateTime.Now.ToString();
                mm.Type   = type;
                _db.Mood.Add(mm);
                _db.SaveChanges();
            }
            return(Ok("set"));
        }
Esempio n. 17
0
 public Comment Create(Comment comment)
 {
     _db.Comments.Add(comment);
     _db.SaveChanges();
     return(comment);
 }
        public ActionResult EditProduct(ProductVM model, HttpPostedFileBase file)
        {
            // Get product id
            int id = model.Id;

            // Populate categories select list and gallery images
            using (DefaultConnection db = new DefaultConnection())
            {
                model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");
            }
            model.GalleryImages = Directory.EnumerateFiles(Server.MapPath("~/Images/Uploads/Products/" + id + "/Gallery/Thumbs"))
                                  .Select(fn => Path.GetFileName(fn));

            // Check model state
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Make sure product name is unique
            using (DefaultConnection db = new DefaultConnection())
            {
                if (db.Products.Where(x => x.Id != id).Any(x => x.Name == model.Name))
                {
                    ModelState.AddModelError("", "That product name is taken!");
                    return(View(model));
                }
            }

            // Update product
            using (DefaultConnection db = new DefaultConnection())
            {
                ProductDTO dto = db.Products.Find(id);

                dto.Name        = model.Name;
                dto.Slug        = model.Name.Replace(" ", "-").ToLower();
                dto.Description = model.Description;
                dto.Price       = model.Price;
                dto.CategoryId  = model.CategoryId;
                dto.ImageName   = model.ImageName;

                CategoryDTO catDTO = db.Categories.FirstOrDefault(x => x.Id == model.CategoryId);
                dto.CategoryName = catDTO.Name;

                db.SaveChanges();
            }

            // Set TempData message
            TempData["SM"] = "You have edited the product!";

            #region Image Upload

            // Check for file upload
            if (file != null && file.ContentLength > 0)
            {
                // Get extension
                string ext = file.ContentType.ToLower();

                // Verify extension
                if (ext != "image/jpg" &&
                    ext != "image/jpeg" &&
                    ext != "image/pjpeg" &&
                    ext != "image/gif" &&
                    ext != "image/x-png" &&
                    ext != "image/png")
                {
                    using (DefaultConnection db = new DefaultConnection())
                    {
                        ModelState.AddModelError("", "The image was not uploaded - wrong image extension.");
                        return(View(model));
                    }
                }

                // Set uplpad directory paths
                var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\Uploads", Server.MapPath(@"\")));

                var pathString1 = Path.Combine(originalDirectory.ToString(), "Products\\" + id.ToString());
                var pathString2 = Path.Combine(originalDirectory.ToString(), "Products\\" + id.ToString() + "\\Thumbs");

                // Delete files from directories

                DirectoryInfo di1 = new DirectoryInfo(pathString1);
                DirectoryInfo di2 = new DirectoryInfo(pathString2);

                foreach (FileInfo file2 in di1.GetFiles())
                {
                    file2.Delete();
                }

                foreach (FileInfo file3 in di2.GetFiles())
                {
                    file3.Delete();
                }

                // Save image name

                string imageName = file.FileName;

                using (DefaultConnection db = new DefaultConnection())
                {
                    ProductDTO dto = db.Products.Find(id);
                    dto.ImageName = imageName;

                    db.SaveChanges();
                }

                // Save original and thumb images

                var path  = string.Format("{0}\\{1}", pathString1, imageName);
                var path2 = string.Format("{0}\\{1}", pathString2, imageName);

                file.SaveAs(path);

                WebImage img = new WebImage(file.InputStream);
                img.Resize(200, 200);
                img.Save(path2);
            }

            #endregion

            // Redirect
            return(RedirectToAction("EditProduct"));
        }
        public ActionResult AddProduct(ProductVM model, HttpPostedFileBase file)
        {
            // Check model state
            if (!ModelState.IsValid)
            {
                using (DefaultConnection db = new DefaultConnection())
                {
                    model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");
                    return(View(model));
                }
            }

            // Make sure product name is unique
            using (DefaultConnection db = new DefaultConnection())
            {
                if (db.Products.Any(x => x.Name == model.Name))
                {
                    model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");
                    ModelState.AddModelError("", "That product name is taken!");
                    return(View(model));
                }
            }

            // Declare product id
            int id;

            // Init and save productDTO
            using (DefaultConnection db = new DefaultConnection())
            {
                ProductDTO product = new ProductDTO();

                product.Name        = model.Name;
                product.Slug        = model.Name.Replace(" ", "-").ToLower();
                product.Description = model.Description;
                product.Price       = model.Price;
                product.CategoryId  = model.CategoryId;

                CategoryDTO catDTO = db.Categories.FirstOrDefault(x => x.Id == model.CategoryId);
                product.CategoryName = catDTO.Name;

                db.Products.Add(product);
                db.SaveChanges();

                // Get the id
                id = product.Id;
            }

            // Set TempData message
            TempData["SM"] = "You have added a product!";

            #region Upload Image

            // Create necessary directories
            var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\Uploads", Server.MapPath(@"\")));

            var pathString1 = Path.Combine(originalDirectory.ToString(), "Products");
            var pathString2 = Path.Combine(originalDirectory.ToString(), "Products\\" + id.ToString());
            var pathString3 = Path.Combine(originalDirectory.ToString(), "Products\\" + id.ToString() + "\\Thumbs");
            var pathString4 = Path.Combine(originalDirectory.ToString(), "Products\\" + id.ToString() + "\\Gallery");
            var pathString5 = Path.Combine(originalDirectory.ToString(), "Products\\" + id.ToString() + "\\Gallery\\Thumbs");

            if (!Directory.Exists(pathString1))
            {
                Directory.CreateDirectory(pathString1);
            }

            if (!Directory.Exists(pathString2))
            {
                Directory.CreateDirectory(pathString2);
            }

            if (!Directory.Exists(pathString3))
            {
                Directory.CreateDirectory(pathString3);
            }

            if (!Directory.Exists(pathString4))
            {
                Directory.CreateDirectory(pathString4);
            }

            if (!Directory.Exists(pathString5))
            {
                Directory.CreateDirectory(pathString5);
            }

            // Check if a file was uploaded
            if (file != null && file.ContentLength > 0)
            {
                // Get file extension
                string ext = file.ContentType.ToLower();

                // Verify extension
                if (ext != "image/jpg" &&
                    ext != "image/jpeg" &&
                    ext != "image/pjpeg" &&
                    ext != "image/gif" &&
                    ext != "image/x-png" &&
                    ext != "image/png")
                {
                    using (DefaultConnection db = new DefaultConnection())
                    {
                        model.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");
                        ModelState.AddModelError("", "The image was not uploaded - wrong image extension.");
                        return(View(model));
                    }
                }

                // Init image name
                string imageName = file.FileName;

                // Save image name to DTO
                using (DefaultConnection db = new DefaultConnection())
                {
                    ProductDTO dto = db.Products.Find(id);
                    dto.ImageName = imageName;

                    db.SaveChanges();
                }

                // Set original and thumb image paths
                var path  = string.Format("{0}\\{1}", pathString2, imageName);
                var path2 = string.Format("{0}\\{1}", pathString3, imageName);

                // Save original
                file.SaveAs(path);

                // Create and save thumb
                WebImage img = new WebImage(file.InputStream);
                img.Resize(200, 200);
                img.Save(path2);
            }

            #endregion

            // Redirect
            return(RedirectToAction("AddProduct"));
        }
Esempio n. 20
0
 public ArticleLike SaveLikeDislike(ArticleLike articleLike)
 {
     _db.ArticleLikes.Add(articleLike);
     _db.SaveChanges();
     return(articleLike);
 }
Esempio n. 21
0
        public void NHanNanum(string url, int idx, EP_KEYWORD EP_KEYWORD)
        {
            try
            {
                FileInfo _finfo = new FileInfo(url);
                if (_finfo.Exists == true)
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load(url);
                    XmlElement  root     = xmldoc.DocumentElement;
                    XmlNodeList nodes    = root.ChildNodes;
                    string      document = "";
                    string      link     = "";
                    string      title    = "";
                    string      category = "";
                    string      tag      = "";

                    foreach (XmlNode node in nodes)
                    {
                        switch (node.Name)
                        {
                        case "title":
                            title = node.InnerText;
                            break;

                        case "category":
                            category = node.InnerText;
                            break;

                        case "link":
                            link = node.InnerText;
                            break;

                        case "description":
                            document = node.InnerText;
                            break;

                        case "tag":
                            tag = node.InnerText;
                            break;
                        }
                    }
                    document = Regex.Replace(document, @"[<][a-z|A-Z|/](.|\n|\r)*?[>]", "");
                    document = document.Replace("\t", " ").Replace("\r", " ").Replace("\n", " ");
                    document = document.Replace("&nbsp;", " ").Replace("&amp;", "").Replace("&quot;", "").Replace("&lt;", "").Replace("&gt;", "");

                    if (document == "")
                    {
                        return;
                    }

                    EP_KEYWORD.ArticleID   = idx;
                    EP_KEYWORD.Count       = -1;
                    EP_KEYWORD.Link        = link;
                    EP_KEYWORD.Description = document;
                    EP_KEYWORD.Title       = title;
                    //EP_KEYWORD.Keyword = sp_tag[i];

                    db.EP_KEYWORD.Add(EP_KEYWORD);
                    db.SaveChanges();

                    if (tag != "")
                    {
                        string[] sp_tag = tag.Split(',');
                        if (sp_tag.Length > 1)
                        {
                            for (int i = 0; i < sp_tag.Length; i++)
                            {
                                EP_KEYWORD.ArticleID = idx;
                                EP_KEYWORD.Count     = 0;
                                //EP_KEYWORD.Link = link;
                                //EP_KEYWORD.Description = document;
                                //EP_KEYWORD.Title = title;
                                EP_KEYWORD.Keyword = sp_tag[i];

                                db.EP_KEYWORD.Add(EP_KEYWORD);
                                db.SaveChanges();
                            }
                        }
                        else
                        {
                            EP_KEYWORD.ArticleID = idx;
                            EP_KEYWORD.Count     = 0;
                            //EP_KEYWORD.Link = link;
                            //EP_KEYWORD.Description = document;
                            //EP_KEYWORD.Title = title;
                            EP_KEYWORD.Keyword = sp_tag[0];

                            db.EP_KEYWORD.Add(EP_KEYWORD);
                            db.SaveChanges();
                        }
                    }



                    //Workflow workflow = WorkflowFactory.getPredefinedWorkflow(WorkflowFactory.WORKFLOW_NOUN_EXTRACTOR);
                    string   newFileName     = "/";
                    string   newFileLocation = HttpContext.Server.MapPath(newFileName);
                    Workflow workflow        = new Workflow(newFileLocation);

                    workflow.appendPlainTextProcessor(new kr.ac.kaist.swrc.jhannanum.plugin.SupplementPlugin.PlainTextProcessor.SentenceSegmentor.SentenceSegmentor(), null);
                    workflow.appendPlainTextProcessor(new kr.ac.kaist.swrc.jhannanum.plugin.SupplementPlugin.PlainTextProcessor.InformalSentenceFilter.InformalSentenceFilter(), null);

                    workflow.setMorphAnalyzer(new kr.ac.kaist.swrc.jhannanum.plugin.MajorPlugin.MorphAnalyzer.ChartMorphAnalyzer.ChartMorphAnalyzer(), "conf/plugin/MajorPlugin/MorphAnalyzer/ChartMorphAnalyzer.json");
                    workflow.appendMorphemeProcessor(new kr.ac.kaist.swrc.jhannanum.plugin.SupplementPlugin.MorphemeProcessor.UnknownMorphProcessor.UnknownProcessor(), null);

                    workflow.setPosTagger(new kr.ac.kaist.swrc.jhannanum.plugin.MajorPlugin.PosTagger.HmmPosTagger.HMMTagger(), "conf/plugin/MajorPlugin/PosTagger/HmmPosTagger.json");
                    workflow.appendPosProcessor(new kr.ac.kaist.swrc.jhannanum.plugin.SupplementPlugin.PosProcessor.NounExtractor.NounExtractor(), null);

                    workflow.activateWorkflow(true);

                    workflow.analyze(document);

                    int                   cnt        = 1;
                    List <Record>         records    = new List <Record>();
                    LinkedList <Sentence> resultList = workflow.getResultOfDocument(new Sentence(0, 0, false));
                    foreach (Sentence s in resultList)
                    {
                        Eojeol[] eojeolArray = s.Eojeols;
                        for (int i = 0; i < eojeolArray.Length; i++)
                        {
                            if (eojeolArray[i].length > 0)
                            {
                                String[] morphemes = eojeolArray[i].Morphemes;
                                for (int j = 0; j < morphemes.Length; j++)
                                {
                                    records.Add(new Record()
                                    {
                                        Id = cnt, Value = morphemes[j]
                                    });
                                    cnt++;
                                }
                            }
                        }
                    }

                    var query = from r in records
                                group r by r.Value into g
                                select new { Count = g.Count(), Value = g.Key };
                    query = query.OrderByDescending(a => a.Count);



                    foreach (var v in query)
                    {
                        if (v.Count > 1 && v.Value[0].ToString() != @"\" && v.Value[0].ToString() != @"&" && v.Value.Length != 1)
                        {
                            EP_KEYWORD.ArticleID = idx;
                            EP_KEYWORD.Count     = v.Count;
                            //EP_KEYWORD.Link = link;
                            //EP_KEYWORD.Description = document;
                            //EP_KEYWORD.Title = title;
                            EP_KEYWORD.Keyword = v.Value;

                            db.EP_KEYWORD.Add(EP_KEYWORD);
                            db.SaveChanges();
                        }
                    }
                    workflow.close();
                }
                else if (_finfo.Exists == false)
                {
                }
            }
            catch (Exception) { }
        }
Esempio n. 22
0
 public void DeleteArticle(int id)
 {
     _db.Articles.Remove(_db.Articles.Find(id));
     _db.SaveChanges();
 }
 public void add(Category category)
 {
     db.Category.Add(category);
     db.SaveChanges();
 }
Esempio n. 24
0
 public int Complete()
 {
     return(_context.SaveChanges());
 }
Esempio n. 25
0
 public void Save()
 {
     db.SaveChanges();
 }
Esempio n. 26
0
 public void Update(AspNetUser aspNetUser)
 {
     _db.AspNetUsers.AddOrUpdate(aspNetUser);
     _db.SaveChanges();
 }
Esempio n. 27
0
 public Role Create(Role role)
 {
     _db.Role.Add(role);
     _db.SaveChanges();
     return(role);
 }
Esempio n. 28
0
        public IHttpActionResult Like(JObject jsonData)
        {
            var lm = new LikeModel();

            dynamic json       = jsonData;
            var     user       = UserViewModel.GetCurrentUser();
            var     liked      = _db.Like.ToList().Where(x => x.Type == Convert.ToInt32(json.type) && x.TypeId == json.typeId.ToString() && x.UserId == user.Id);
            var     likeModels = liked as LikeModel[] ?? liked.ToArray();

            if (!likeModels.Any())
            {
                lm.Id     = Guid.NewGuid().ToString();
                lm.Type   = json.type;
                lm.UserId = user.Id;
                lm.TypeId = json.typeId.ToString();
                _db.Like.Add(lm);
                if (json.type == 1)
                {
                    DietModel d = _db.Diet.Find(json.typeId.ToString());
                    d.Likes++;
                    _db.Entry(d).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 2)
                {
                    FitnessModel f = _db.Fitness.Find(json.typeId.ToString());
                    f.Likes++;
                    _db.Entry(f).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 3)
                {
                    HealthModel h = _db.Health.Find(json.typeId.ToString());
                    h.Likes++;
                    _db.Entry(h).State = System.Data.Entity.EntityState.Modified;
                }
                _db.SaveChanges();
                return(Ok(lm));
            }
            else
            {
                var like = likeModels.First();

                _db.Like.Remove(like);
                if (json.type == 1)
                {
                    DietModel d = _db.Diet.Find(json.typeId.ToString());
                    d.Likes            = d.Likes - 1;
                    _db.Entry(d).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 2)
                {
                    FitnessModel f = _db.Fitness.Find(json.typeId.ToString());
                    f.Likes            = f.Likes - 1;
                    _db.Entry(f).State = System.Data.Entity.EntityState.Modified;
                }
                if (json.type == 3)
                {
                    HealthModel h = _db.Health.Find(json.typeId.ToString());
                    h.Likes            = h.Likes - 1;
                    _db.Entry(h).State = System.Data.Entity.EntityState.Modified;
                }
                _db.SaveChanges();
                return(Ok());
            }
        }
Esempio n. 29
0
 public ActionResult EditUser(UsersInRolesModel model /*AspNetUser aspNetUser*/)
 {
     db.Entry(model).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("UsersWithRoles"));
 }
        public ActionResult ReserveringToevoegenPost(ReserveringModel reserveringsModel)
        {
            reserveringsModel.Velden        = repository.Velds.ToList();
            reserveringsModel.Plaatsen      = repository.Plaatss.ToList();
            reserveringsModel.Reserveringen = repository.Reserverings.Where(p => p.BeginDatum >= reserveringsModel.Reservering.BeginDatum && p.BeginDatum <= reserveringsModel.Reservering.EindDatum || p.EindDatum <= reserveringsModel.Reservering.BeginDatum && p.EindDatum >= reserveringsModel.Reservering.EindDatum).ToList();
            reserveringsModel.Boekingen     = repository.Boekings.Where(d => d.BeginDatum >= reserveringsModel.Reservering.BeginDatum && d.BeginDatum <= reserveringsModel.Reservering.EindDatum || d.EindDatum <= reserveringsModel.Reservering.BeginDatum && d.EindDatum >= reserveringsModel.Reservering.EindDatum).ToList();

            Reservering resv = new Reservering
            {
                BeginDatum     = reserveringsModel.Reservering.BeginDatum,
                EindDatum      = reserveringsModel.Reservering.EindDatum,
                Email          = reserveringsModel.Reservering.Email,
                Naam           = reserveringsModel.Reservering.Naam,
                Telnr          = reserveringsModel.Reservering.Telnr,
                PlaatsId       = reserveringsModel.Reservering.PlaatsId,
                AantalPersonen = reserveringsModel.Reservering.AantalPersonen
            };

            resv.Plaats = reserveringsModel.Plaatsen.Where(p => p.PlaatsID.Equals(reserveringsModel.Reservering.PlaatsId)).First();


            if (reserveringsModel.Reserveringen != null)
            {
                int i = 0;


                foreach (var id in reserveringsModel.Reserveringen)
                {
                    idList.Add(id.PlaatsId);
                }
                foreach (var idB in reserveringsModel.Boekingen)
                {
                    if (!idList.Contains(idB.PlaatsId))
                    {
                        idList.Add(idB.PlaatsId);
                    }
                }

                var resvIdArray = idList.ToArray();
                var PlaatsArray = reserveringsModel.Plaatsen.ToArray();

                while (i <= PlaatsArray.Length)
                {
                    if (resvIdArray.Contains(PlaatsArray[i].PlaatsID))
                    {
                        i++;

                        if (i == PlaatsArray.Length)
                        {
                            //throw new Exception("Geen plek");

                            return(RedirectToAction("GeenPlek"));
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        resv.PlaatsId = PlaatsArray[i].PlaatsID;
                    }

                    resv.Plaats = reserveringsModel.Plaatsen.Where(p => p.PlaatsID.Equals(reserveringsModel.Reservering.PlaatsId)).First();
                    resv.VeldID = reserveringsModel.Velden.Where(p => p.VeldID.Equals(resv.PlaatsId)).First().VeldID;
                    resv.Plaats = null;

                    if (ModelState.IsValid)
                    {
                        if (reserveringsModel.Reservering.EindDatum > reserveringsModel.Reservering.BeginDatum)
                        {
                            db.Reserverings.Add(resv);
                            db.SaveChanges();
                            return(RedirectToAction("ReserveringSucces"));
                        }
                    }
                    return(View(reserveringsModel));
                }
            }

            else
            {
                if (ModelState.IsValid)
                {
                    if (reserveringsModel.Reservering.EindDatum > reserveringsModel.Reservering.BeginDatum)
                    {
                        resv.Plaats = reserveringsModel.Plaatsen.Where(p => p.PlaatsID.Equals(reserveringsModel.Reservering.PlaatsId)).First();
                        resv.VeldID = reserveringsModel.Velden.Where(p => p.VeldID.Equals(resv.PlaatsId)).First().VeldID;
                        db.Reserverings.Add(resv);
                        db.SaveChanges();
                        return(RedirectToAction("ReserveringSucces"));
                    }
                }

                return(View(reserveringsModel));
            }

            return(View(reserveringsModel));
        }
        public ActionResult EditBoekingPost(BoekingViewModel reserveringsModel)
        {
            reserveringsModel.Velden   = repository.Velds.Where(p => p.VeldID.Equals(reserveringsModel.Reserv.VeldID)).ToList();
            reserveringsModel.Plaatsen = repository.Plaatss.Where(p => p.VeldID.Equals(reserveringsModel.Reserv.VeldID)).ToList();
            Plaats GekozenPlaats = reserveringsModel.Plaatsen.First();
            Veld   GekozenVeld   = reserveringsModel.Velden.FirstOrDefault();

            reserveringsModel.Resveringens = repository.Reserverings.Where(p => p.BeginDatum >= reserveringsModel.Reserv.BeginDatum && p.BeginDatum <= reserveringsModel.Reserv.EindDatum || p.EindDatum <= reserveringsModel.Reserv.BeginDatum && p.EindDatum >= reserveringsModel.Reserv.EindDatum).ToList();
            reserveringsModel.Boekings     = repository.Boekings.Where(p => p.BeginDatum >= reserveringsModel.Boeking.BeginDatum && p.BeginDatum <= reserveringsModel.Boeking.EindDatum || p.EindDatum <= reserveringsModel.Boeking.BeginDatum && p.EindDatum >= reserveringsModel.Boeking.EindDatum).ToList();

            if (GekozenPlaats == null)
            {
                db.SaveChanges();
                return(RedirectToAction("ReserveringSucces", "Bezoeker", new { area = "" }));
            }

            if (reserveringsModel.Resveringens != null)
            {
                int i = 0;


                foreach (var id in reserveringsModel.Resveringens)
                {
                    idList.Add(id.PlaatsId);
                }
                foreach (var id in reserveringsModel.Boekings)
                {
                    if (!idList.Contains(id.PlaatsId))
                    {
                        idList.Add(id.PlaatsId);
                    }
                }

                var resvIdArray = idList.ToArray();
                var PlaatsArray = reserveringsModel.Plaatsen.ToArray();

                while (i <= PlaatsArray.Length)
                {
                    if (resvIdArray.Contains(PlaatsArray[i].PlaatsID))
                    {
                        i++;

                        if (i == PlaatsArray.Length)
                        {
                            //throw new Exception("Geen plek");

                            return(RedirectToAction("GeenPlek", "Bezoeker", new { area = "" }));
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        reserveringsModel.Reserv.PlaatsId = PlaatsArray[i].PlaatsID;
                    }


                    if (ModelState.IsValid)
                    {
                        if (reserveringsModel.Reserv.EindDatum > reserveringsModel.Reserv.BeginDatum)
                        {
                            db.Entry(reserveringsModel.Boeking).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            return(RedirectToAction("ReserveringSucces", "Bezoeker", new { area = "" }));
                        }
                    }

                    return(View(reserveringsModel));
                }
            }

            else
            {
                if (ModelState.IsValid)
                {
                    if (reserveringsModel.Reserv.EindDatum > reserveringsModel.Reserv.BeginDatum)
                    {
                        db.Entry(reserveringsModel.Reserv).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("ReserveringSucces", "Bezoeker", new { area = "" }));
                    }
                }

                return(View(reserveringsModel));
            }

            return(View(reserveringsModel));
        }
Esempio n. 32
0
 //public Article CreateArticle(Article article)
 //{
 //    return _iArticleRepository.CreateArticle(article);
 //}
 public Article CreateArticle(Article article)
 {
     _db.Articles.Add(article);
     _db.SaveChanges();
     return(article);
 }
 public CommentReport SaveReport(CommentReport commentReport)
 {
     _db.CommentReports.Add(commentReport);
     _db.SaveChanges();
     return(commentReport);
 }
Esempio n. 34
0
 public bool Post(SMI_Treasury treasury)
 {
     BD.SMI_Treasury.Add(treasury);
     return(BD.SaveChanges() > 0);
 }
Esempio n. 35
0
 public ActionResult Create(Customer cus)
 {
     db.Customers.Add(cus);
     db.SaveChanges();
     return(RedirectToAction("ShowToCart", "ShoppingCart"));
 }
Esempio n. 36
0
        public ActionResult Create([Bind(Include = "ID,UserID,publish,publish_SITE,Publish_ID,Publish_PW,Publish_BLOGID,Publish_BLOGKEY")] EP_METAS eP_METAS, string SERVICE)
        {
            if (ModelState.IsValid)
            {
                if (SERVICE == "Tistory")
                {
                    try
                    {
                        string[]   strarray    = eP_METAS.publish_SITE.Split('/');
                        MetaWeblog api         = new MetaWeblog("http://" + strarray[2] + "/api");
                        Post[]     check_login = new Post[1];
                        check_login = api.getRecentPosts(eP_METAS.Publish_BLOGID, eP_METAS.Publish_ID, eP_METAS.Publish_PW, 1);
                    }
                    catch
                    {
                        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                        return(View());
                    }
                }
                if (SERVICE == "Naver")
                {
                    try
                    {
                        string[]   strarray    = eP_METAS.publish_SITE.Split('/');
                        MetaWeblog api         = new MetaWeblog("https://api.blog.naver.com/xmlrpc");
                        Post[]     check_login = new Post[1];
                        check_login = api.getRecentPosts(eP_METAS.Publish_BLOGID, eP_METAS.Publish_ID, eP_METAS.Publish_BLOGKEY, 1);
                    }
                    catch
                    {
                        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                        return(View());
                    }
                }
                if (SERVICE == "WordPress")
                {
                    try
                    {
                        string[]   strarray    = eP_METAS.publish_SITE.Split('/');
                        MetaWeblog api         = new MetaWeblog(eP_METAS.publish_SITE + "/xmlrpc.php");
                        Post[]     check_login = new Post[1];
                        check_login = api.getRecentPosts("", eP_METAS.Publish_ID, eP_METAS.Publish_PW, 1);
                    }
                    catch
                    {
                        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                        //return View();
                        return(RedirectToAction("Create", "BlogAPI", new { SERVICE = "WordPress" }));
                    }
                }
                //if (SERVICE == "Blogger")
                //{
                //    try
                //    {
                //        string[] strarray = eP_METAS.publish_SITE.Split('/');
                //        MetaWeblog api = new MetaWeblog("http://www.blogger.com/feeds/" + eP_METAS.ID +"/posts/default");

                //        Post[] check_login = new Post[1];
                //        check_login = api.getRecentPosts("", eP_METAS.Publish_ID, eP_METAS.Publish_PW, 1);
                //    }
                //    catch
                //    {
                //        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                //        return View();

                //    }
                //}
                eP_METAS.publish = SERVICE;
                eP_METAS.UserID  = User.Identity.GetUserId();
                //eP_METAS.publish = ViewData["Metaservice"].ToString;
                db.EP_META.Add(eP_METAS);
                db.SaveChanges();
                return(RedirectToAction("Manage", "Account"));
            }

            return(View(eP_METAS));
        }