Esempio n. 1
0
        public async Task <IActionResult> Edit(Abouts about)
        {
            var abouts = _context.Abouts.Where(r => r.ID == about.ID);

            if (abouts.Any())
            {
                try
                {
                    var data = abouts.FirstOrDefault();
                    data.Title       = about.Title;
                    data.Content     = about.Content;
                    data.PublishDate = about.PublishDate;
                    data.DownDate    = about.DownDate;
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(StatusCode(Status400BadRequest, new ResponseMessage {
                        Message = ex.Message
                    }));
                }
            }
            else
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = "查無資訊"
                }));
            }
        }
        public ActionResult DeleteConfirmed(byte id)
        {
            Abouts abouts = db.Abouts.Find(id);

            db.Abouts.Remove(abouts);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "AboutId,ImageUrl,Description,Title")] Abouts abouts)
 {
     if (ModelState.IsValid)
     {
         db.Entry(abouts).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(abouts));
 }
        public ActionResult Create([Bind(Include = "AboutId,ImageUrl,Description,Title")] Abouts abouts)
        {
            if (ModelState.IsValid)
            {
                db.Abouts.Add(abouts);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(abouts));
        }
Esempio n. 5
0
 public Response <Abouts> DeleteAbouts([FromBody] Abouts about)
 {
     try
     {
         return(_aboutBusiness.DeleteAbouts(about));
     }
     catch (Exception e)
     {
         _logger.Error($"DeleteAbouts Failed: {e.Message}\n {e.StackTrace}");
         return(new Response <Abouts>(false, e.Message, null));
     }
 }
        // GET: AdminPage/Abouts/Delete/5
        public ActionResult Delete(byte?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Abouts abouts = db.Abouts.Find(id);

            if (abouts == null)
            {
                return(HttpNotFound());
            }
            return(View(abouts));
        }
Esempio n. 7
0
 public List <Abouts> DeleteAbouts(Abouts about)
 {
     try
     {
         var result = ListByStoredProcedure <Abouts>(StoredProc.DeleteAbouts,
                                                     new StoredProcedureParameter("AboutID", about.AboutID, DbType.Int32));
         return(result);
     }
     catch (Exception e)
     {
         _logger.Error($"DeleteAbouts Failed: {e.Message}\n {e.StackTrace}");
         return(new List <Abouts>());
     }
 }
Esempio n. 8
0
 public Response <Abouts> UpdateAbouts([FromBody] Abouts about)
 {
     try
     {
         var osPrincipal = (UserIdentity)System.Web.HttpContext.Current.User;
         var userData    = JsonConvert.DeserializeObject <UserViewModel>(osPrincipal.UserData);
         about.LastUpdatedBy = userData.CodeUserName;
         return(_aboutBusiness.UpdateAbouts(about));
     }
     catch (Exception e)
     {
         _logger.Error($"UpdateAbouts Failed: {e.Message}\n {e.StackTrace}");
         return(new Response <Abouts>(false, e.Message, null));
     }
 }
Esempio n. 9
0
        public async Task <IActionResult> Create(Abouts about)
        {
            try
            {
                _context.Abouts.Add(about);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = ex.Message
                }));
            }
        }
Esempio n. 10
0
 public Response <Abouts> DeleteAbouts(Abouts abouts)
 {
     try
     {
         var data = _aboutRepository.DeleteAbouts(abouts);
         if (data != null && data.Any())
         {
             return(new Response <Abouts>(true, "Success", data[0]));
         }
         return(new Response <Abouts>(false, "Fail", null));
     }
     catch (Exception e)
     {
         _logger.Error($"DeleteAbouts Failed: {e.Message}\n {e.StackTrace}");
         return(new Response <Abouts>(false, e.Message, null));
     }
 }
Esempio n. 11
0
 public List <Abouts> UpdateAbouts(Abouts about)
 {
     try
     {
         var result = ListByStoredProcedure <Abouts>(StoredProc.UpdateAbouts,
                                                     new StoredProcedureParameter("AboutID", about.AboutID, DbType.Int32)
                                                     , new StoredProcedureParameter("Name", about.Name, DbType.String)
                                                     , new StoredProcedureParameter("Description", about.Description, DbType.String)
                                                     , new StoredProcedureParameter("Image", about.Image, DbType.String)
                                                     , new StoredProcedureParameter("Detail", about.Detail, DbType.String)
                                                     , new StoredProcedureParameter("Status", about.Status, DbType.Boolean)
                                                     , new StoredProcedureParameter("LastUpdatedBy", about.LastUpdatedBy, DbType.String)
                                                     , new StoredProcedureParameter("LastUpdatedDate", about.LastUpdatedDate, DbType.DateTime));
         return(result);
     }
     catch (Exception e)
     {
         _logger.Error($"UpdateAbouts Failed: {e.Message}\n {e.StackTrace}");
         return(new List <Abouts>());
     }
 }