示例#1
0
        public async Task <IHttpActionResult> Delete(int id)
        {
            string methodNameStr = $"StudentController().Delete({id})";

            try
            {
                logger.Log(LogLevel.Info, $"{MakeLogStr4Entry(methodNameStr)}.");
                using (var context = new SampDB())
                {
                    var repos = new GenericDataRepository(context);
                    var res   = await repos.DeleteAsync <Student>(id);

                    if (res == HttpStatusCode.OK)
                    {
                        await context.SaveChangesAsync();
                    }
                    logger.Log(LogLevel.Info, $"{MakeLogStr4Exit(methodNameStr)} {res}");
                    return(Content(res, res.ToString()));
                }
            }
            catch (Exception e)
            {
                logger.Log(LogLevel.Error, $"{MakeLogStr4Exit(methodNameStr)}:\r\n{e}");
                return(Content(HttpStatusCode.InternalServerError, HttpStatusCode.InternalServerError.ToString()));
            }
        }