Beispiel #1
0
        public ActionResult DeleteBannerApplication(int id)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    Int32[] AtchId            = new int[db.BALinkReqDocs.Where(x => x.BannerApplicationID == id).Count()];
                    var     bannerApplication = new TradingLicense.Entities.BannerApplication()
                    {
                        BannerApplicationID = id
                    };
                    int cnt = 0;
                    foreach (var item in db.BALinkReqDocs.Where(x => x.BannerApplicationID == id))
                    {
                        AtchId[cnt] = Convert.ToInt32(item.AttachmentID);
                        cnt         = cnt + 1;
                    }
                    foreach (var item in AtchId)
                    {
                        db.BALinkReqDocs.RemoveRange(db.BALinkReqDocs.Where(x => x.AttachmentID == item));
                        db.SaveChanges();
                        db.Attachments.RemoveRange(db.Attachments.Where(x => x.AttachmentID == item));
                        db.SaveChanges();
                    }

                    db.Entry(bannerApplication).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                    transaction.Commit();
                    return(Json(new { success = true, message = " Deleted Successfully" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(Json(new { success = false, message = "Error While Delete Record" }, JsonRequestBehavior.AllowGet));
                }
            }
        }