public async Task <Response <bool> > ToggleActivate(int?id) { try { var model = db.Customer.Find(id); if (model == null) { return(new Response <bool>(Constants.NOT_FOUND_CODE, false, Constants.NOT_FOUND)); } var user = model.User; if (user.Id == (await GetCurrentUserIdAsync())) { return(new Response <bool>(Constants.SOMETHING_WRONG_CODE, false, Constants.SOMETHING_WRONG)); } user.IsActive = !user.IsActive; db.Update(user); db.SaveChanges(); Message = Toast.SucsessToast(); return(new Response <bool>(Constants.SUCCESS_CODE, true, Constants.SUCCESS)); } catch (Exception exc) { Serilog.Log.Error(exc, $"controller: Customers", $"action : ToggleActivate"); Message = Toast.ErrorToast(); return(new Response <bool>(Constants.SOMETHING_WRONG_CODE, false, GetExceptionMessage(exc))); } }
// GET: Admin/ContactUs/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var contactUs = await db.ContactUs .Include(c => c.Customer) .FirstOrDefaultAsync(m => m.Id == id); if (contactUs == null) { return(NotFound()); } try { contactUs.IsRead = true; db.Update(contactUs); await db.SaveChangesAsync(); } catch (Exception e) { Message = Toast.ErrorToast(GetExceptionMessage(e)); } return(View(contactUs)); }
public async Task <IActionResult> Create([Bind("Id,Name,DisplayName,IsVisible,ItemOrder,Title,Description,AnchorText,AnchorUrl,ImageUrl")] ContentManagement contentManagement, IFormCollection formCollection) { try { if (ModelState.IsValid) { if (formCollection?.Files?.Count > 0) { FileInfo fi = new FileInfo(formCollection.Files[0].FileName); var newFilename = "P" + contentManagement.Id + "_" + string.Format("{0:d}", (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension; var webPath = _hostingEnvironment.WebRootPath; var path = Path.Combine("", webPath + @"\uploads\images\ContentManagement\" + newFilename); var pathToSave = @"/uploads/images/ContentManagement/" + newFilename; using (var stream = new FileStream(path, FileMode.Create)) { formCollection.Files[0].CopyTo(stream); } contentManagement.ImageUrl = pathToSave; } _context.Add(contentManagement); await _context.SaveChangesAsync(); Message = Toast.SucsessToast(); return(RedirectToAction(nameof(Index))); } return(View(contentManagement)); } catch (Exception e) { Message = Toast.ErrorToast(GetExceptionMessage(e)); return(View(contentManagement)); } }
public async Task <IActionResult> Index() { try { var user = await GetCurrentUserAsync(); var customer = user.Customer; return(View(customer.Request.ToList())); } catch (Exception e) { Message = Toast.ErrorToast(GetExceptionMessage(e)); return(View(new List <Request>())); } }
protected string GetExceptionMessage(Exception e) { var ExceptionMessageFormSettings = config.Value.ExceptionMessage; bool GetExceptionMessage = false; if (ExceptionMessageFormSettings != null) { GetExceptionMessage = true; } if (GetExceptionMessage) { if (e.InnerException != null) { return(e.InnerException.Message); } return(e.Message); } return(Toast.ErrorToast().Message); }
protected string GetExceptionMessage(Exception e) { if (config == null) { config = HttpContext.RequestServices.GetService <IOptions <MyConfiguration> >(); } var ExceptionMessageFormSettings = config.Value.ExceptionMessage; bool GetExceptionMessage = false; if (ExceptionMessageFormSettings != null) { GetExceptionMessage = true; } if (GetExceptionMessage) { if (e.InnerException != null) { return(e.InnerException.Message); } return(e.Message); } return(Toast.ErrorToast().Message); }