コード例 #1
0
 /// <summary>
 /// Create Author Logic
 /// </summary>
 public static string UpdateAuthor(int id, string refrence, string fullName, string image, string country)
 {
     try
     {
         using (DbContext = new LibraryAppDbEntities())
         {
             if (string.IsNullOrEmpty(refrence) || string.IsNullOrEmpty(fullName) || string.IsNullOrEmpty(image) || string.IsNullOrEmpty(country))
             {
                 return("something is empty");
             }
             else
             {
                 // Check if The New Author is Already Exist
                 var updatedAuthor = DbContext.Authors.FirstOrDefault(a => a.Id == id);
                 if (updatedAuthor != null)
                 {
                     updatedAuthor.AuthorRef      = refrence;
                     updatedAuthor.AuthorFullName = fullName;
                     updatedAuthor.Picture        = image;
                     updatedAuthor.Country        = country;
                     DbContext.SaveChanges();
                     return("OK");
                 }
                 else
                 {
                     return("Reference Must Be Unique");
                 }
             }
         }
     }
     catch (Exception)
     {
     }
     return("OK");
 }
コード例 #2
0
ファイル: CRUDAuteur.aspx.cs プロジェクト: ID-JA/AllinOne
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            // noDeleteMessage.Visible = false;
            try
            {
                using (DbContext = new LibraryAppDbEntities())
                {
                    var deletedAuthor = DbContext.Authors.FirstOrDefault(a => a.AuthorRef == txtDeleteAuthor.Value);
                    if (deletedAuthor == null)
                    {
                        findOperaMessage.InnerText = "You Try To Delete Record Doesn't Exist...";
                        findOperaMessage.Visible   = true;
                    }
                    else
                    {
                        // => Remove Author Image From Server
                        File.Delete(Server.MapPath("~/Images/") + deletedAuthor.Picture);

                        //=> Delete Author From Database
                        DbContext.Authors.Remove(deletedAuthor);
                        DbContext.SaveChanges();

                        LoadAuthorGridView();
                    }
                    ClearControls("delete");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
 /// <summary>
 /// Create Author Logic
 /// </summary>
 public static string AddAuthor(string refrence, string fullName, string image, string country)
 {
     try
     {
         using (DbContext = new LibraryAppDbEntities())
         {
             if (string.IsNullOrEmpty(refrence) || string.IsNullOrEmpty(fullName) || string.IsNullOrEmpty(image) || string.IsNullOrEmpty(country))
             {
                 return("something is empty");
             }
             else
             {
                 // Check if The New Author is Already Exist
                 var AuthorAlreadyExist = DbContext.Authors.FirstOrDefault(a => a.AuthorRef == refrence);
                 if (AuthorAlreadyExist == null)
                 {
                     Author newAuthor = new Author
                     {
                         AuthorRef      = refrence,
                         AuthorFullName = fullName,
                         Picture        = image,
                         Country        = country
                     };
                     DbContext.Authors.Add(newAuthor);
                     DbContext.SaveChanges();
                     return("OK");
                 }
                 else
                 {
                     return("Already Exist");
                 }
             }
         }
     }
     catch (Exception)
     {
     }
     return("OK");
 }