Exemple #1
0
        public ActionResult Update(Publication publication)
        {
            List <MySqlParameter> parameters = new List <MySqlParameter>();
            string TimeOfViewParam           = "@tov";

            if (publication.TimeOfView > 0)
            {
                parameters.Add(new MySqlParameter("@tov", publication.TimeOfView));
            }
            else
            {
                TimeOfViewParam = "default";
            }

            if (publication.ExpiryDate < DateTime.Now.Date)
            {
                ViewBag.Status        = false;
                ViewBag.StatusMessage = "Please input Expiry Date.";
                return(View());
            }

            parameters.Add(new MySqlParameter("@expdate", publication.ExpiryDate));
            bool rlt = Mysqldb.Update($"update publications set TimeOfView={TimeOfViewParam}, ExpiryDate=@expdate where ID={publication.ID}", parameters);

            if (rlt)
            {
                ViewBag.Status        = true;
                ViewBag.StatusMessage = "Publication Updated Successfully.";
                TempData["ID"]        = publication.ID;
                PublicationsOnChange(publication.GetHashCode());
            }
            return(View(publication));
        }
Exemple #2
0
        public ActionResult Delete(int id)
        {
            Mysqldb.Delete($"delete from publications where ID={id}");
            Publication pub = new Publication
            {
                ID = id
            };

            PublicationsOnChange(pub.GetHashCode());
            return(RedirectToAction("Index", "Management"));
        }
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (BookId != null ? BookId.GetHashCode() : 0);
         result = (result * 397) ^ (Title != null ? Title.GetHashCode() : 0);
         result = (result * 397) ^ (Author != null ? Author.GetHashCode() : 0);
         result = (result * 397) ^ (Publication != null ? Publication.GetHashCode() : 0);
         result = (result * 397) ^ (Date != null ? Date.GetHashCode() : 0);
         return(result);
     }
 }
Exemple #4
0
        public ActionResult Create(Publication publication)
        {
            if (publication.Image != null)
            {
                using (Stream istream = publication.Image.InputStream)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        publication.Image.InputStream.CopyTo(ms);
                        byte[] image = ms.ToArray();

                        var    Parameters      = new List <MySqlParameter>();
                        string TimeOfViewParam = "default";
                        if (publication.TimeOfView > 0)
                        {
                            TimeOfViewParam = "@tov";
                            Parameters.Add(new MySqlParameter("@tov", publication.TimeOfView));
                        }

                        if (publication.ExpiryDate < DateTime.Now.Date)
                        {
                            ViewBag.Status        = false;
                            ViewBag.StatusMessage = "Please input Expiry Date.";
                            return(View());
                        }

                        Parameters.AddRange(new MySqlParameter[]
                        {
                            new MySqlParameter("@expdate", publication.ExpiryDate.Date.ToString("yyyy-MM-dd")),
                            new MySqlParameter("@image", image)
                        });
                        if (Mysqldb.Insert($"insert into publications(TimeOfView,ExpiryDate,Image) values({TimeOfViewParam},@expdate,@image)", Parameters))
                        {
                            ViewBag.Status        = true;
                            ViewBag.StatusMessage = "Publication Added Successfully.";
                            PublicationsOnChange(publication.GetHashCode());
                        }
                    }
                }
            }
            else
            {
                ViewBag.Status        = false;
                ViewBag.StatusMessage = "Publication adding failed.";
            }
            return(View());
        }
Exemple #5
0
        public ActionResult Update(int id = 0)
        {
            Publication pub = new Publication();

            TempData["ID"] = id;
            if (id > 0)
            {
                DataSet ds = Mysqldb.Select($"select * from publications where ID={id}");
                if (ds.Tables.Count > 0)
                {
                    pub.ID         = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"].ToString());
                    pub.TimeOfView = Convert.ToInt32(ds.Tables[0].Rows[0]["TimeOfView"].ToString());
                    pub.ExpiryDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["ExpiryDate"].ToString());
                    PublicationsOnChange(pub.GetHashCode());
                }

                return(View(pub));
            }

            return(View());
        }