Beispiel #1
0
 /// <summary>
 /// Save
 /// </summary>
 /// <param name="model">model</param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper Save(CetificateModel model)
 {
     try
     {
         using (var _context = new TDHEntities())
         {
             PN_CETIFICATE _md = new PN_CETIFICATE();
             if (model.Insert)
             {
                 _md.id = Guid.NewGuid();
             }
             else
             {
                 _md = _context.PN_CETIFICATE.FirstOrDefault(m => m.id == model.ID && !m.deleted && m.created_by == model.CreateBy);
                 if (_md == null)
                 {
                     throw new DataAccessException(FILE_NAME, "Save", model.CreateBy);
                 }
             }
             _md.name     = model.Name;
             _md.school   = model.School;
             _md.time     = model.Time;
             _md.ordering = model.Ordering;
             _md.publish  = model.Publish;
             //Setting value don't allow change when create or edit
             if (model.Insert)
             {
                 _md.created_by   = model.CreateBy;
                 _md.created_date = DateTime.Now;
                 _context.PN_CETIFICATE.Add(_md);
                 _context.Entry(_md).State = EntityState.Added;
             }
             else
             {
                 _md.updated_by   = model.UpdateBy;
                 _md.updated_date = DateTime.Now;
                 _context.PN_CETIFICATE.Attach(_md);
                 _context.Entry(_md).State = EntityState.Modified;
             }
             _context.SaveChanges();
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "Save", model.CreateBy, ex);
     }
     if (model.Insert)
     {
         Notifier.Notification(model.CreateBy, Message.InsertSuccess, Notifier.TYPE.Success);
     }
     else
     {
         Notifier.Notification(model.CreateBy, Message.UpdateSuccess, Notifier.TYPE.Success);
     }
     return(ResponseStatusCodeHelper.Success);
 }
Beispiel #2
0
 /// <summary>
 /// Delete
 /// </summary>
 /// <param name="model">model</param>
 /// <returns>ResponseStatusCodeHelper</returns>
 public ResponseStatusCodeHelper Delete(CetificateModel model)
 {
     try
     {
         using (var _context = new TDHEntities())
         {
             PN_CETIFICATE _md = _context.PN_CETIFICATE.FirstOrDefault(m => m.id == model.ID && !m.deleted && m.created_by == model.CreateBy);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "Delete", model.CreateBy);
             }
             _md.deleted      = true;
             _md.deleted_by   = model.DeleteBy;
             _md.deleted_date = DateTime.Now;
             _context.PN_CETIFICATE.Attach(_md);
             _context.Entry(_md).State = EntityState.Modified;
             _context.SaveChanges();
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "Delete", model.CreateBy, ex);
     }
     Notifier.Notification(model.CreateBy, Message.DeleteSuccess, Notifier.TYPE.Success);
     return(ResponseStatusCodeHelper.Success);
 }
Beispiel #3
0
 /// <summary>
 /// Get item
 /// </summary>
 /// <param name="model">model</param>
 /// <returns>MoneyCetificateModel</returns>
 public CetificateModel GetItemByID(CetificateModel model)
 {
     try
     {
         using (var _context = new TDHEntities())
         {
             PN_CETIFICATE _md = _context.PN_CETIFICATE.FirstOrDefault(m => m.id == model.ID && !m.deleted && m.created_by == model.CreateBy);
             if (_md == null)
             {
                 throw new DataAccessException(FILE_NAME, "GetItemByID", model.CreateBy);
             }
             return(new CetificateModel()
             {
                 ID = _md.id,
                 Name = _md.name,
                 School = _md.school,
                 Time = _md.time,
                 Ordering = _md.ordering,
                 Publish = _md.publish
             });
         }
     }
     catch (DataAccessException fieldEx)
     {
         throw fieldEx;
     }
     catch (Exception ex)
     {
         throw new ServiceException(FILE_NAME, "GetItemByID", model.CreateBy, ex);
     }
 }