Esempio n. 1
0
        public Users create(Users newUser)
        {
            var usr = _context.Add(newUser).Entity;

            _context.SaveChanges();
            return(usr);
        }
        public Machine Subscribe(Machine serviceInfo)
        {
            var result = _context.Machines.Add(serviceInfo);

            _context.SaveChanges();
            return(result.Entity);
        }
Esempio n. 3
0
        public async Task <IActionResult> PostFile([FromRoute] short id, IFormFile uploadedFile)
        {
            try
            {
                using (var memoryStream = new MemoryStream())
                {
                    var val = new File();
                    val.Name = uploadedFile.FileName;
                    await uploadedFile.CopyToAsync(memoryStream);

                    val.Text = Encoding.UTF8.GetString(memoryStream.ToArray());
                    _dbContext.Files.Add(val);
                    _dbContext.SaveChanges();
                }
                // process uploaded files
                // Don't rely on or trust the FileName property without validation.

                return(Ok());
            }
            catch (Exception ex)
            {
                this.logger.LogWarning("", ex);
                return(BadRequest());
            }
        }
 public ActionResult <ResponseModel> PutAdd([FromBody] BookModel _book)
 {
     // var exist = _context.book.SingleOrDefault(tb => tb.user == _book.user && tb.book == _book.book);
     // if (exist != null) {
     //    return new ResponseModel
     //    {
     //        status = 404,
     //        statusText = "failure",
     //    };
     // }
     _book.datetime = DateTime.Now;
     _context.book.Add(_book);
     if (_context.SaveChanges() > 0)
     {
         var added = _context.book.SingleOrDefault(tb => tb.user == _book.user && tb.book == _book.book && tb.datetime == _book.datetime);
         return(new ResponseModel
         {
             status = 200,
             statusText = "success",
             data = added
         });
     }
     else
     {
         return(new ResponseModel
         {
             status = 404,
             statusText = "failure",
         });
     }
 }
Esempio n. 5
0
        public void InsertHashDataForTrack(IEnumerable <HashedFingerprint> hashes, IModelReference trackReference)
        {
            var subFingerprints = hashes.Select(hash => CopyToSubFingerprint(trackReference, hash))
                                  .ToList();

            _context.SubFingerprint.AddRange(subFingerprints);
            _context.SaveChanges();
        }
Esempio n. 6
0
        public ActionResult <ResponseModel> PostInsert([FromBody] RequestModel req)
        {
            var todo  = new ToDoModel();
            var data  = new Newtonsoft.Json.Linq.JObject();
            var token = new AuthModel();

            try
            {
                todo.name    = (string)req.data["name"];
                todo.content = (string)req.data["content"];
                if ((string)req.data["token"]["token"] != HttpContext.Session.GetString("token"))
                {
                    throw new Exception();
                }
                token.id      = (int)req.data["token"]["id"];
                token.token   = (string)req.data["token"]["token"];
                token         = _context.Auth.Single(item => item.id == token.id && item.token == token.token);
                todo.uuid     = token.uuid;
                todo.name     = (string)req.data["name"];
                todo.content  = (string)req.data["content"];
                todo.datetime = DateTime.Now;
                _context.ToDo.Add(todo);
                _context.SaveChanges();
                todo             = _context.ToDo.Single(item => item.name == todo.name && item.content == todo.content && item.datetime == todo.datetime);
                data["id"]       = todo.id;
                data["name"]     = todo.name;
                data["content"]  = todo.content;
                data["datetime"] = todo.datetime;
            }
            catch (Exception ex) {
                data["msg"] = ex.Message;
                return(new ResponseModel
                {
                    status = 404,
                    statusText = "failure",
                    data = data
                });
            }

            return(new ResponseModel
            {
                status = 200,
                statusText = "success",
                data = data,
            });
        }
Esempio n. 7
0
        public ActionResult <ResponseModel> PostRegister([FromBody] RequestModel req)
        {
            var user = new UserModel
            {
                uuid     = UUIDModel.GetUUID(),
                name     = (string)req.data["name"],
                password = (string)req.data["password"],
                datetime = DateTime.Now
            };

            _context.User.Add(user);
            _context.SaveChanges();

            return(new ResponseModel
            {
                status = 200,
                statusText = "success"
            });
        }
Esempio n. 8
0
        public async Task <IActionResult> PostFile(IFormFile uploadedFile)
        {
            try
            {
                using (var memoryStream = new MemoryStream())
                {
                    var val = new Value();
                    val.Name = uploadedFile.FileName;
                    await uploadedFile.CopyToAsync(memoryStream);

                    val.Image = memoryStream.ToArray();
                    _dbContext.Values.Add(val);
                    _dbContext.SaveChanges();
                }
                // process uploaded files
                // Don't rely on or trust the FileName property without validation.

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Esempio n. 9
0
        public void Save(Customer customer)
        {
            var existing = (from c in _dbContext.Customers
                            where c.Id == customer.Id
                            select c).SingleOrDefault();

            if (existing == null)
            {
                _dbContext.Customers.Add(customer);
            }
            else
            {
                existing.FirstName = customer.FirstName;
                existing.LastName  = customer.LastName;
            }
            _dbContext.SaveChanges();
        }
Esempio n. 10
0
        public IActionResult NewUser([FromBody] User obj)

        {
            User user = new User();

            user.Name  = obj.Name;
            user.Email = obj.Email;
            try
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(Ok(user));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }
Esempio n. 11
0
        public ActionResult Login(string userName, string pwd)
        {
            User us = null;

            try
            {
                User u = _context.User.ToList().Where(n => (n.LoginName == userName || n.Email == userName || n.Phone == userName) && n.PassWord == pwd).FirstOrDefault();
                if (u != null)
                {
                    us = u;
                    u.LastLoginTime = DateTime.Now;
                    _context.SaveChanges();
                    return(Ok(u));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(NotFound(ex.Message));
            }
        }
Esempio n. 12
0
 public void Commit() => context.SaveChanges();
Esempio n. 13
0
        public static IHost Seed(this IHost host)
        {
            using IServiceScope scope = host.Services.CreateScope();
            SQLiteDbContext context = scope.ServiceProvider.GetService <SQLiteDbContext>();

            if (context.Users.Any())
            {
                return(host);
            }

            var userRole  = new Role("User");
            var adminRole = new Role("Admin");

            string uRoleId  = context.Roles.Add(userRole).Entity.Id;
            string uRoleId2 = uRoleId;
            string aRoleId  = context.Roles.Add(adminRole).Entity.Id;

            var hasher = new PasswordHasher <User>();
            var user1  = new User
            {
                FirstName = "Teszt",
                LastName  = "Elek",
                UserName  = "******",
                BirthDate = new DateTime(1996, 6, 5),
                Email     = "*****@*****.**",
                Address   = "Itthon",
                RoleId    = uRoleId
            };

            user1.PasswordHash = hasher.HashPassword(user1, "123456789aA!");

            var user2 = new User
            {
                FirstName = "Hans",
                LastName  = "Regenkurt",
                UserName  = "******",
                BirthDate = new DateTime(1978, 10, 9),
                Email     = "*****@*****.**",
                Address   = "Otthon",
                RoleId    = uRoleId2
            };

            user2.PasswordHash = hasher.HashPassword(user2, "123456789aA!");

            var admin = new User
            {
                FirstName = "John",
                LastName  = "Doe",
                UserName  = "******",
                BirthDate = new DateTime(1992, 4, 20),
                Email     = "*****@*****.**",
                Address   = "Somewhere",
                RoleId    = aRoleId
            };

            admin.PasswordHash = hasher.HashPassword(admin, "123456789aA!");

            context.Users.Add(user1);
            context.Users.Add(user2);
            context.Users.Add(admin);

            var car1 = new Car
            {
                Brand             = "VW",
                Model             = "Golf",
                Colour            = Colour.TurmericYellow,
                EngineDescription = "1.4 TSI, 122HP, 200Nm",
                LicensePlate      = "RPP-469",
                Mileage           = 6.5
            };

            var car2 = new Car
            {
                Brand             = "BMW",
                Model             = "5",
                Colour            = Colour.Blue,
                EngineDescription = "2.5 TFSI, 300HP, 600Nm",
                LicensePlate      = "FGH-420",
                Mileage           = 8.3,
            };

            Premise premise = context.Premises.Add(new Premise
            {
                Address = "Tiszaújváros Iparipark út 4.",
                Name    = "Rent a Car"
            }).Entity;

            car1.PremiseId = premise.Id;
            car2.PremiseId = premise.Id;

            context.Cars.Add(car1);
            context.Cars.Add(car2);

            context.SaveChanges();
            return(host);
        }