Exemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     author author = new author();
     author.Name = textBox1.Text;
     author.InsertAuth(author.Name);
     Close();
 }
Exemplo n.º 2
0
        // GET: authors/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            author author = db.authors.Find(id);

            if (author == null)
            {
                return(HttpNotFound());
            }
            return(View(author));
        }
Exemplo n.º 3
0
        public void CreateDB()
        {
            db = new Database(_connectionStringName);
            db.Execute(@"

DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS authors;

CREATE TABLE posts (
	id				bigint AUTO_INCREMENT NOT NULL,
	title			varchar(127) NOT NULL,
	author			bigint NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

CREATE TABLE authors (
	id				bigint AUTO_INCREMENT NOT NULL,
	name			varchar(127) NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

			"            );


            var a1 = new author();

            a1.name = "Bill";
            db.Insert(a1);

            var a2 = new author();

            a2.name = "Ted";
            db.Insert(a2);

            var p = new post();

            p.title  = "post1";
            p.author = a1.id;
            db.Insert(p);

            p        = new post();
            p.title  = "post2";
            p.author = a1.id;
            db.Insert(p);

            p        = new post();
            p.title  = "post3";
            p.author = a2.id;
            db.Insert(p);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Build an Author object from the database
        /// </summary>
        /// <param name="i">
        /// the LINQ data object to build from
        /// </param>
        /// <returns>
        /// returns an Author object
        /// </returns>

        private static Author FillRecord(author i)
        {
            Author result = null;

            if (i != null)
            {
                result          = new Author();
                result.id       = i.id;
                result.username = i.username;
                result.password = i.password;
                result.salt     = i.salt;
            }
            return(result);
        }
Exemplo n.º 5
0
        protected virtual void opProject()
        {
            author aux_author = SelectedAuthor;

            if (SelectedAuthor != null)
            {
                this.Dialogs.Add(new ProjectesViewModel(aux_author, true, context)
                {
                    context             = context,
                    Boto_afegir_enabled = true,
                    ProjectsL           = new ObservableCollection <project>(SelectedAuthor.projects.ToList()),
                });
            }
        }
Exemplo n.º 6
0
        // GET: authors/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            author author = db.authors.Find(id);

            if (author == null)
            {
                return(HttpNotFound());
            }
            return(View(author));
        }
        // GET: authors/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            author author = await db.authors.FindAsync(id);

            if (author == null)
            {
                return(HttpNotFound());
            }
            return(View(author));
        }
Exemplo n.º 8
0
        public static author AddAuthor(author author, AppUser AppUser)
        {
            Dictionary <string, object> Params   = ObjectUtil.FillMap(author);
            Dictionary <string, object> RespPost = Transaction.PostInput(Transaction.URL, "addAuthor", AppUser, Params);

            if (RespPost != null && RespPost["result"].ToString() == "0")
            {
                Dictionary <string, object> DataMap   = StringUtil.JSONStringToMap(RespPost["data"].ToString());
                Dictionary <string, object> authorMap = StringUtil.JSONStringToMap(DataMap["author"].ToString());
                author Newauthor = (author)ObjectUtil.FillObjectWithMap(new author(), authorMap);
                return(Newauthor);
            }
            return(null);
        }
Exemplo n.º 9
0
        public async Task CreateDbAsync()
        {
            db = Database.Create <MySqlConnection>(ConnectionStrings.Get(_connectionStringName));
            await db.ExecuteAsync(@"

DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS authors;

CREATE TABLE posts (
	id				bigint AUTO_INCREMENT NOT NULL,
	title			varchar(127) NOT NULL,
	author			bigint NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

CREATE TABLE authors (
	id				bigint AUTO_INCREMENT NOT NULL,
	name			varchar(127) NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

			"            );


            var a1 = new author();

            a1.name = "Bill";
            await db.InsertAsync(a1);

            var a2 = new author();

            a2.name = "Ted";
            await db.InsertAsync(a2);

            var p = new post();

            p.title  = "post1";
            p.author = a1.id;
            await db.InsertAsync(p);

            p        = new post();
            p.title  = "post2";
            p.author = a1.id;
            await db.InsertAsync(p);

            p        = new post();
            p.title  = "post3";
            p.author = a2.id;
            await db.InsertAsync(p);
        }
Exemplo n.º 10
0
        public override object Update(object Obj)
        {
            author author = (author)Obj;

            Refresh();
            author DBAuthor = (author)GetById(author.id);

            if (DBAuthor == null)
            {
                return(null);
            }
            dbEntities.Entry(DBAuthor).CurrentValues.SetValues(author);
            dbEntities.SaveChanges();
            return(author);
        }
Exemplo n.º 11
0
        public ActionResult DeleteConfirmed(string id)
        {
            author author = db.authors.Find(id);

            db.authors.Remove(author);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(RedirectToAction("../Home/Error"));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
        public ActionResult Create(author author)
        {
            author.au_id    = author.phone;
            author.contract = true;

            if (ModelState.IsValid)
            {
                db.authors.Add(author);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
        public static authorViewModel ConvertToViewModel(this author authorIn)
        {
            authorViewModel avm = new authorViewModel(authorIn.id);

            avm.LastName  = authorIn._lname;
            avm.FirstName = authorIn._fname;
            avm.Phone     = authorIn._phone;
            avm.Address   = authorIn._address;
            avm.City      = authorIn._city;
            avm.State     = authorIn._state;
            avm.Zip       = authorIn._zip;
            avm.Contract  = authorIn._contract ? "Yes" : "No";

            return(avm);
        }
Exemplo n.º 14
0
        // GET: authors/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            author author = db.authors.Find(id);

            if (author == null)
            {
                return(HttpNotFound());
            }
            ViewBag.file_id = new SelectList(db.files, "file_id", "file_link", author.file_id);
            return(View(author));
        }
Exemplo n.º 15
0
		public async Task CreateDbAsync()
		{
			db = new Database(_connectionStringName);
			await db.ExecuteAsync(@"

DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS authors;

CREATE TABLE posts (
	id				bigint AUTO_INCREMENT NOT NULL,
	title			varchar(127) NOT NULL,
	author			bigint NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

CREATE TABLE authors (
	id				bigint AUTO_INCREMENT NOT NULL,
	name			varchar(127) NOT NULL,
	PRIMARY KEY (id)
) ENGINE=INNODB;

			");


			var a1 = new author();
			a1.name = "Bill";
			await db.InsertAsync(a1);

			var a2 = new author();
			a2.name = "Ted";
			await db.InsertAsync(a2);

			var p = new post();
			p.title = "post1";
			p.author = a1.id;
			await db.InsertAsync(p);

			p = new post();
			p.title = "post2";
			p.author = a1.id;
			await db.InsertAsync(p);

			p = new post();
			p.title = "post3";
			p.author = a2.id;
			await db.InsertAsync(p);

		}
Exemplo n.º 16
0
        // POST api/Author
        public HttpResponseMessage Postauthor(author author)
        {
            if (ModelState.IsValid)
            {
                db.authors.Add(author);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, author);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = author.authorid }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
        public string ajaxEditnameAuthor()
        {
            int    id   = Convert.ToInt32(Request["pk"]);
            string name = Request["value"];

            author author = new author();

            author.author_id   = id;
            author.author_name = name;

            db.authors.AddOrUpdate(author);

            db.SaveChanges();

            return("");
        }
Exemplo n.º 18
0
        public ActionResult EditAuthors(author author)
        {
            var query = db.authors.SingleOrDefault(x => x.id == author.id);

            query.name    = author.name;
            query.surname = author.surname;
            db.SaveChanges();

            var modelquery = db.authors.Select(x => new Authors
            {
                Name    = x.name,
                Surname = x.surname,
                Id      = x.id
            }).ToList();

            return(View("~/Views/Authors/AuthorsView.cshtml", modelquery));
        }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "au_id,au_lname,au_fname,phone,address,city,state,zip,contract")] author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             return(RedirectToAction("../Home/Error"));
         }
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
Exemplo n.º 20
0
        public ActionResult Create(author a)
        {
            if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission())
            {
                if (ModelState.IsValid)
                {
                    AuthorService.StoreAuthor(a);
                    TempData["Alert"] = AlertView.Build("Du har skapat författaren " + a.FirstName + " " + a.LastName, AlertType.Success);
                    return(RedirectToAction("Start"));
                }

                return(View(a));
            }


            return(Redirect("/Error/Code/403"));
        }
Exemplo n.º 21
0
            public post MapIt(post p, author a)
            {
                // Get existing author object, or if not found store this one
                author aExisting;

                if (authors.TryGetValue(a.id, out aExisting))
                {
                    a = aExisting;
                }
                else
                {
                    authors.Add(a.id, a);
                }

                // Wire up objects
                p.author_obj = a;
                return(p);
            }
Exemplo n.º 22
0
        // POST api/author
        public IHttpActionResult Post(author author)
        {
            // if empty data
            if (author == null || string.IsNullOrWhiteSpace(author.first_name) || string.IsNullOrWhiteSpace(author.last_name) || string.IsNullOrWhiteSpace(author.login) || string.IsNullOrWhiteSpace(author.password))
            {
                return(Json(new { registrationSuccess = false, errorMessage = "Braki w następujących polach: imię, nazwisko, login, hasło" }));
            }

            // if login exists in db
            List <author> authorsFromDb = db.author.Select(x => x).ToList();

            if (authorsFromDb != null && authorsFromDb.Any(x => x.login == author.login))
            {
                return(Json(new { registrationSuccess = false, errorMessage = "Istnieje już autor o tym loginie" }));
            }

            // if problem in hashing password or getting group for author
            var hashedPassword = PasswordHelper.HashPassword(author.password);
            var groupForAuthor = db.group.FirstOrDefault(x => x.name == "Author");

            if (hashedPassword == null || groupForAuthor == null)
            {
                return(Json(new { registrationSuccess = false, errorMessage = "Wystąpił błąd. Przepraszamy za kłopoty techniczne" }));
            }

            // if everything ok
            // add log
            var group  = db.group.FirstOrDefault(x => x.name == "Author");
            var newLog = db.log.Add(new log()
            {
                author     = author,
                event_name = LogTypesEnum.CREATE.ToString(),
                event_date = DateTime.Now
            });

            // add author details
            author.password = hashedPassword;
            author.group    = group;
            author.status   = StatusesEnum.ACTIVE.ToString();

            db.SaveChanges();
            return(Json(new { registrationSuccess = true }));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Deletes a specific Author from the database
        /// </summary>
        /// <param name="id">
        /// the unique identifier of the author to delete
        /// </param>
        /// <returns>
        /// returns true when deleted, false if not
        /// </returns>

        public static bool Delete(long id)
        {
            author t = (from author in db.authors where author.id == id select author).FirstOrDefault();

            if (t != null)
            {
                try
                {
                    db.authors.DeleteOnSubmit(t);
                    db.SubmitChanges();
                }
                catch (ChangeConflictException)
                {
                    db.ChangeConflicts.ResolveAll(RefreshMode.OverwriteCurrentValues);
                    db.SubmitChanges();
                }
            }
            return(t != null);
        }
        public ActionResult Create([Bind(Include = "author_id,first_name,last_name,nationality,uploadedAuthorImage,description")] author author)
        {
            if (ModelState.IsValid)
            {
                // Uplaod Photo =======================================================================================================
                string ImageName      = Path.GetFileNameWithoutExtension(author.uploadedAuthorImage.FileName); // get name
                string ImageExtension = Path.GetExtension(author.uploadedAuthorImage.FileName);                // get extension
                ImageName    = ImageName + '_' + DateTime.Now.ToString("yymmssfff") + ImageExtension;          // Not To Repeat
                author.photo = "~/Uploads/Photos/authors/" + ImageName;                                        // Save To DB
                ImageName    = Path.Combine(Server.MapPath("~/Uploads/Photos/authors/"), ImageName);           // Combine To Local Folder
                author.uploadedAuthorImage.SaveAs(ImageName);

                db.authors.Add(author);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
Exemplo n.º 25
0
        protected virtual void delAutor()
        {
            if (SelectedAuthor != null)
            {
                author aux_author = SelectedAuthor;

                if ((!(aux_author.projects.Count > 0)))
                {
                    delAuthorWithOutProject();
                }
                else if ((aux_author.projects.Count > 0))
                {
                    delAuthorWithProject();
                }
            }
            else
            {
                MessageBox.Show("Cap autor seleccionat");
            }
        }
Exemplo n.º 26
0
        public async Task <JsonResult> putPost(author Author, string path1, string path2, string path3, string path4, string path, string title, string hl, bool?show, bool?active)
        {
            string pathlast = string.Join("/", new string[]
            {
                path1, path2, path3, path4, path
            }.Where(a => a != null));

            hl = hl ?? "EN";

            post post;

            post = await db.posts.FirstOrDefaultAsync(a => a.revisions.Any(b => b.path == pathlast && b.lang == hl.ToUpper()));

            if (post == null)
            {
                post            = new post();
                post.created_at = DateTime.Now;
                post.author_id  = Author.id;
                post.show       = show ?? true;
                post.active     = active ?? true;
                db.posts.Add(post);
            }

            revision r = new revision();

            r.post = post;
            db.revision.Add(r);

            r.title      = title;
            r.created_at = DateTime.Now;
            r.lang       = hl.ToUpper();
            r.path       = pathlast;
            r.author_id  = Author.id;
            r.active     = active ?? true;

            r.data = await new StreamReader(Request.Body, Encoding.UTF8).ReadToEndAsync();

            await db.SaveChangesAsync();

            return(Json(new { post_id = post.id, revision_id = r.id }));
        }
Exemplo n.º 27
0
        public ActionResult AddAuthors(author author)
        {
            var any = db.authors.SingleOrDefault(c => c.id == author.id && c.name == author.name && c.surname == author.surname);

            if (any != null)
            {
                ViewBag.ExistanceError = "This author already exists";
                return(View("~/Views/Authors/AddAuthor.cshtml"));
            }

            db.authors.Add(author);
            db.SaveChanges();
            var modelquery = db.authors.Select(x => new Authors
            {
                Name    = x.name,
                Surname = x.surname,
                Id      = x.id
            }).ToList();

            return(View("~/Views/Authors/AuthorsView.cshtml", modelquery));
        }
Exemplo n.º 28
0
        public ActionResult Edit(author formInput)
        {
            if (ModelState.IsValid)
            {
                //the author object is tracked by the pubsEntities database context
                var author = (from a in db.authors
                              where a.au_id == formInput.au_id
                              select a).SingleOrDefault();

                author.au_fname = formInput.au_fname;
                author.au_lname = formInput.au_lname;
                author.phone    = formInput.phone;
                //author.city = formInput.city;

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(formInput));
        }
Exemplo n.º 29
0
        public static List <author> AuthorList(AppUser AppUser, int Offset, int Limit, Dictionary <string, object> Params)
        {
            List <author> authors = new List <author>();
            List <Dictionary <string, object> > authorListMap = UniversalObjList(AppUser, Offset, Limit, Params, "authorList");

            if (authorListMap == null || authorListMap.Count == 0)
            {
                return(authors);
            }

            foreach (Dictionary <string, object> authorMap in authorListMap)
            {
                if (authorMap.Keys.Count == 1 && authorMap.Keys.ElementAt(0).Equals("count"))
                {
                    continue;
                }

                author author = (author)ObjectUtil.FillObjectWithMap(new author(), authorMap);
                authors.Add(author);
            }
            return(authors);
        }
Exemplo n.º 30
0
        public IHttpActionResult Deleteauthor(int id)
        {
            author author = db.authors.Find(id);
            var    ab     = db.authors_books.FirstOrDefault(x => x.author_id == id);

            while (ab != null)
            {
                db.authors_books.Remove(ab);
                db.SaveChanges();
                ab = db.authors_books.FirstOrDefault(x => x.author_id == id);
            }

            if (author == null)
            {
                return(NotFound());
            }

            db.authors.Remove(author);
            db.SaveChanges();

            return(Ok(author));
        }
Exemplo n.º 31
0
        // DELETE api/Author/5
        public HttpResponseMessage Deleteauthor(short id)
        {
            author author = db.authors.Find(id);

            if (author == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.authors.Remove(author);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, author));
        }
Exemplo n.º 32
0
        private void btnAddAuth_Click(object sender, EventArgs e)
        {
            author objAuth = new author();
            String strAuthor = lstAuthor.Text;            
            if (bookRep.GetAuthorDetails(strAuthor).Rows.Count > 0)
            {
                MessageBox.Show("Author already present");
                return;
            }
            objAuth.AuthorID = bookRep.GetMaxID("authors", "authorid")+1;
            objAuth.AuthorName = strAuthor;

            bookRep.InsertAuthors(objAuth);
            lstAuthor.DataSource = bookRep.GetAuthorDetails();
            lstAuthor.DisplayMember = "Authorname";
            lstAuthor.ValueMember = "AuthorId";
            //setLstValue(lstAuthor, strAuthor);
            lstAuthor.Text = strAuthor;
            autoAuthors.Clear();
            foreach (DataRowView dr in lstAuthor.Items)
                autoAuthors.Add(dr.Row[1].ToString());
            lstAuthor.AutoCompleteSource = AutoCompleteSource.CustomSource;
            lstAuthor.AutoCompleteCustomSource = autoAuthors;
        }
Exemplo n.º 33
0
            public post MapIt(post p, author a)
            {
                // Get existing author object, or if not found store this one
                author aExisting;
                if (authors.TryGetValue(a.id, out aExisting))
                    a = aExisting;
                else
                    authors.Add(a.id, a);

                // Wire up objects
                p.author_obj = a;
                return p;
            }
Exemplo n.º 34
0
            public author MapIt(author a, post p)
            {
                // Terminating call.  Since we can return null from this function
                // we need to be ready for PetaPoco to callback later with null
                // parameters
                if (a == null)
                    return current;

                // Is this the same author as the current one we're processing
                if (current != null && current.id == a.id)
                {
                    // Yes, just add this post to the current author's collection of posts
                    current.posts.Add(p);

                    // Return null to indicate we're not done with this author yet
                    return null;
                }

                // This is a different author to the current one, or this is the
                // first time through and we don't have an author yet

                // Save the current author
                var prev = current;

                // Setup the new current author
                current = a;
                current.posts = new List<post>();
                current.posts.Add(p);

                // Return the now populated previous author (or null if first time through)
                return prev;
            }
Exemplo n.º 35
0
        public bool loadXMLAtom(channel ch, string rss)
        {
            using (DataSet rssData = new DataSet())
            {
                System.IO.StringReader sr = new System.IO.StringReader(rss);
                DataSet ds2 = new DataSet();
                rssData.ReadXml(sr, XmlReadMode.Auto);
                string str = rssData.GetXmlSchema();

                if (rssData.Tables.Contains("feed"))
                {
                    foreach (DataRow dataRow in rssData.Tables["feed"].Rows)
                    {
                        int c = rssData.Tables.Count;

                        if (rssData.Tables.Contains("link"))
                        {
                            foreach (DataRow dr in rssData.Tables["link"].Rows)
                            {
                                ch.link = dataRowContains("href", dr, rssData);
                                break;
                            }
                        }
                        //dataRowContains("title", dataRow, rssData);
                        //rss_sub.set_title(ch.title);
                        ch.description = dataRowContains("subtitle", dataRow, rssData);//Convert.ToString(dataRow["subtitle"]);
                        ch.pubDate = dataRowContains("updated", dataRow, rssData);//Convert.ToString(dataRow["updated"]);
                        int counter = 0;
                        if (rssData.Tables.Contains("entry"))
                        {
                            foreach (DataRow itemRow in rssData.Tables["entry"].Rows)
                            {
                                Item inside = new Item();
                                inside.titleI = dataRowContains("title", itemRow, rssData);//Convert.ToString(itemRow["title"]);
                                inside.descriptionI = dataRowContains("summary", itemRow, rssData);//Convert.ToString(itemRow["summary"]);
                                inside.linkI = dataRowContains("id", itemRow, rssData);//Convert.ToString(rssData.Tables["id"]);
                                inside.pubDateI = dataRowContains("updated", itemRow, rssData);//Convert.ToString(itemRow["updated"]);
                                if (inside.pubDateI == "")
                                {
                                    inside.pubDateI = dataRowContains("issued", itemRow, rssData);
                                }
                                inside.subscription = ch.title;
                                if (rssData.Tables.Contains("link"))
                                {
                                    foreach (DataRow dr in rssData.Tables["link"].Rows)
                                    {
                                        if (dr["href"].ToString().Contains(".html"))
                                        {
                                            inside.linkI = dr["href"].ToString();
                                        }
                                    }
                                }
                                if (rssData.Tables.Contains("author"))
                                {
                                    //foreach (DataRow authorRow in rssData.Tables["author"].Rows)
                                    DataRow authorRow = rssData.Tables["author"].Rows[0];
                                    //foreach (DataRow authorRow in itemRow["author"])
                                    {
                                        author auth = new author();
                                        auth.name = dataRowContains("name", authorRow, rssData);
                                        auth.email = dataRowContains("email", authorRow, rssData);
                                        inside.authors.Add(auth);
                                    }
                                }
                                ch.item.Add(inside);

                                counter++;
                                if (counter > ch.maxItems) { break; }
                            }
                        }
                        /*if (findChannelName(ch.title) == null)
                        {
                            channels.Add(ch);
                        }*/
                    }

                }
                return true;
            }
        }