Example #1
0
        public string Add(DocumentInfoModel item)
        {
            using (ScorelinkEntities db = new ScorelinkEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = db.Database.BeginTransaction())
                {
                    try
                    {
                        var docInfo = new DocumentInfo
                        {
                            FileUID    = item.FileUID,
                            FileName   = item.FileName,
                            FilePath   = item.FilePath,
                            CreateBy   = item.CreateBy,
                            CreateDate = DateTime.Parse(item.CreateDate)
                        };

                        db.DocumentInfoes.Add(docInfo);
                        db.SaveChanges();

                        //var lastuser = db.Users.Select(x => x.UserId).Max();

                        dbTran.Commit();

                        return("OK");
                    }
                    catch (Exception ex)
                    {
                        dbTran.Rollback();
                        return(ex.ToString());
                    }
                }
            }
        }
Example #2
0
        public string Delete(string id)
        {
            using (ScorelinkEntities db = new ScorelinkEntities())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = db.Database.BeginTransaction())
                {
                    try
                    {
                        var user = db.DocumentInfoes.Where(x => x.DocId.ToString() == id).First();
                        db.DocumentInfoes.Remove(user);

                        db.SaveChanges();
                        dbTran.Commit();

                        return("OK");
                    }
                    catch (Exception ex)
                    {
                        dbTran.Rollback();
                        return(ex.ToString());
                    }
                }
            }
        }