public virtual IActionResult AddReview(
            [FromQuery] string loginToken,
            [FromBody] Review body)
        {
            if (string.IsNullOrEmpty(loginToken))
            {
                return(BadRequest("Login token is required"));
            }
            var loggedInUser = _tokenizer.ValidateToken(loginToken);

            if (loggedInUser != null)
            {
                if (body != null)
                {
                    body.AuditEnteredBy = loggedInUser;
                    body.AuditEntered   = DateTime.Now;
                    body.AuditUpdatedBy = loggedInUser;
                    body.AuditUpdated   = DateTime.Now;
                    _dbContext.Reviews.Add(body);
                    _dbContext.SaveChanges();
                }
                if (body != null && body.Id != null)
                {
                    return(new OkObjectResult(body));
                }
                else
                {
                    return(NotFound("Record was not added"));
                }
            }
            else
            {
                return(BadRequest("Invalid or expired login token"));
            }
        }
示例#2
0
 public void Add(Author newAuthor)
 {
     _context.Authors.Add(
         new DbAuthor {
         Id = newAuthor.Id, Name = newAuthor.Name
     });
     _context.SaveChanges();
 }
 public void Add(Book newBook)
 {
     _context.Books.Add(
         new DbBook {
         Id       = newBook.Id,
         Title    = newBook.Title,
         AuthorId = newBook.Author.Id
     });
     _context.SaveChanges();
 }
        /// <summary>
        /// Constructor for Controller
        /// </summary>
        /// <param name="apiDataContext">API Data Context</param>
        /// <param name="logger">ILoggerFactory</param>
        public ContributorBaseApiController(ApiDataContext apiDataContext, ILoggerFactory logger)
        {
            _logger    = logger.CreateLogger <ContributorBaseApiController>();
            _dbContext = apiDataContext;
            _dbContext.Database.EnsureCreated();

            var count = _dbContext.Contributors.Count();

            if (count == 0)
            {
                // Add default administrator
                _dbContext.Contributors.Add(
                    new Contributor
                {
                    Name        = "Default Administrator",
                    Description = "Default system administrator",
                    Email       = "*****@*****.**",
                    Password    = _tokenizer.GetSHA1HashData("Default#Admin#Password777"),
                    Comments    = "This account should be disabled or deleted (in favor of a better admin account) in production"
                }
                    );
                // Add default unit tester
                _dbContext.Contributors.Add(
                    new Contributor
                {
                    Name        = "Default Unit Tester",
                    Description = "Default unit test run account",
                    Email       = "*****@*****.**",
                    Password    = _tokenizer.GetSHA1HashData("Unit#Test#Password2018"),
                    Comments    = "This account should be disabled or deleted in production"
                }
                    );
                _dbContext.SaveChanges();
            }
        }
示例#5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="jwtOptions"></param>
        /// <param name="loggerFactory"></param>
        /// <param name="cloutApiDataContext"></param>
        public JwtController(IOptions <JwtIssuerOptions> jwtOptions, ILoggerFactory loggerFactory, ApiDataContext cloutApiDataContext)
        {
            _jwtOptions = jwtOptions.Value;
            ThrowIfInvalidOptions(_jwtOptions);

            _logger = loggerFactory.CreateLogger <JwtController>();

            _serializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };

            _dbContext = cloutApiDataContext;
            _dbContext.Database.EnsureCreated();
            var jwtCount = _dbContext.JwtUsers.Count();

            if (jwtCount == 0)
            {
                _dbContext.JwtUsers.Add(new JwtUser {
                    UserName = "******",
                    Password = _tokenizer.GetSHA1HashData("DefaultApplicationPassword")
                });
                _dbContext.SaveChanges();
            }
        }
示例#6
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors((builder) =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowAnyOrigin();
            });

            app.Map("/project/list", (builder) =>
            {
                builder.Run(async(context) =>
                {
                    var dc    = new ApiDataContext();
                    var model = dc.Projects.ToList();

                    await context.Response.WriteAsync(JsonConvert.SerializeObject(model));
                });
            });

            app.Map("/employee/list", (builder) =>
            {
                builder.Run(async(context) =>
                {
                    var dc    = new ApiDataContext();
                    var model = dc.Employees.ToList();

                    await context.Response.WriteAsync(JsonConvert.SerializeObject(model));
                });
            });

            app.Map("/employee/update", (builder) =>
            {
                builder.Run(async(context) =>
                {
                    var stream = new StreamReader(context.Request.Body);
                    var json   = stream.ReadToEnd();

                    var sendedEmployee = JsonConvert.DeserializeObject <Employee>(json);

                    var dc          = new ApiDataContext();
                    var model       = dc.Employees.FirstOrDefault(e => e.Id == sendedEmployee.Id);
                    model.Age       = sendedEmployee.Age;
                    model.Name      = sendedEmployee.Name;
                    model.ProjectId = sendedEmployee.ProjectId;
                    model.Salary    = sendedEmployee.Salary;

                    dc.SaveChanges();

                    await context.Response.WriteAsync("Kayıt başarıyla güncellendi");
                });
            });

            app.Run(async(context) =>
            {
                new ApiDataContext().Database.EnsureCreated();

                await context.Response.WriteAsync("Hello World!");
            });
        }