public AuthModel CreateAuthModel(AuthModel authModel)
        {
            var createdAuthModel = _authDbContext.AuthModel.Add(authModel);

            _authDbContext.SaveChanges();
            return(createdAuthModel.Entity);
        }
Exemplo n.º 2
0
        public AuthInfo CreateAuthInfo(AuthInfo authInfo)
        {
            var createdAuthInfo = _authDbContext.AuthInfo.Add(authInfo);

            _authDbContext.SaveChanges();
            return(createdAuthInfo.Entity);
        }
Exemplo n.º 3
0
        private void DeleteRelatedDate(Device device)
        {
            var ud = _context.UserDevices.Where(ud => ud.Device.DeviceId == device.DeviceId);

            _context.RemoveRange(ud);
            _context.SaveChanges();
        }
Exemplo n.º 4
0
        public void ExpireSession(AppUser user, Guid sessionId)
        {
            AuthSession session = _authDbContext.AuthSessions
                                  .Single(s => s.User == user && s.Id == sessionId && s.ExpiredTime == null);

            session.ExpiredTime = SystemClock.Instance.GetCurrentInstant();

            _authDbContext.SaveChanges();
        }
 private void DeleteRelatedData(Category category)
 {
     foreach (var device in category.Devices)
     {
         var ud = _context.UserDevices.Where(ud => ud.Device.DeviceId == device.DeviceId);
         _context.RemoveRange(ud);
         _context.SaveChanges();
     }
 }
Exemplo n.º 6
0
        public string SetConnection(string username, DateTime expire)
        {
            var id = Guid.NewGuid().ToString();

            db.Connections.Add(new Connection {
                ConnectionId = id, Username = username, ExpireDate = expire
            });
            db.SaveChanges();
            return(id);
        }
Exemplo n.º 7
0
        public IActionResult Put(int id, ParkingProfileViewModel model)
        {
            if (id == 0 && model == null)
            {
                return(null);
            }

            var parking = _dbContext.parkings
                          .FirstOrDefault(p => p.ParkingId == id);
            var facilities = _dbContext.ParkingFacilities
                             .FirstOrDefault(p => p.Parking.ParkingId == parking.ParkingId);

            if (parking == null)
            {
                return(NotFound());
            }



            parking.Name        = model.Name;
            parking.Description = model.Description;
            parking.City        = model.City;
            parking.Address     = model.Address;

            var result = _dbContext.Update(parking);

            if (_dbContext.SaveChanges() > 0)
            {
                if (facilities == null)
                {
                    var facility = new ParkingFacilities()
                    {
                        Parking        = parking,
                        GuestRoom      = model.GuestRoom,
                        OnlinePayment  = model.OnlinePayment,
                        ServiceStation = model.ServiceStation
                    };

                    _dbContext.Add(facilities);
                    _dbContext.SaveChanges();
                }
                else
                {
                    facilities.ServiceStation = model.ServiceStation;
                    facilities.OnlinePayment  = model.OnlinePayment;
                    facilities.GuestRoom      = model.GuestRoom;
                    _dbContext.Update(facilities);
                    _dbContext.SaveChanges();
                }
            }


            return(Ok());
        }
Exemplo n.º 8
0
        //This methos should be used to Create a new User
        public bool CreateUser(User user)
        {
            context.Users.Add(user);
            int returnValue = context.SaveChanges();

            return(returnValue > 0 ? true : false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Stores an XML Element to the database
        /// </summary>
        /// <param name="element">XML Element</param>
        /// <param name="friendlyName">Friendly Name</param>
        public void StoreElement(XElement element, string friendlyName)
        {
            if (element == null)
            {
                throw new ArgumentException("Element is null", nameof(element));
            }

            var entity = _db.DataProtectionKeys.SingleOrDefault(k => k.FriendlyName == friendlyName);

            if (null != entity)
            {
                entity.XmlData = element.ToString();
                _db.DataProtectionKeys.Update(entity);
            }
            else
            {
                _db.DataProtectionKeys.Add(new DataProtectionKey
                {
                    FriendlyName = friendlyName,
                    XmlData      = element.ToString()
                });
            }

            _db.SaveChanges();
        }
        public IActionResult Post([FromForm] IFormFile file, int id)
        {
            if (file == null && id == 0)
            {
                return(null);
            }

            ParkingImages model = new ParkingImages();

            using (var memoryStream = new MemoryStream())
            {
                file.CopyToAsync(memoryStream);
                model.Image = memoryStream.ToArray();
            }

            model.Parking = _context.parkings.FirstOrDefault(p => p.ParkingId == id);

            var result = _context.Add(model);

            if (_context.SaveChanges() == 0)
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public IActionResult Post([FromForm] IFormFile file, int id)
        {
            var park = _context.parkings.FirstOrDefault(p => p.ParkingId == id);



            if (park == null)
            {
                return(NotFound());
            }
            using (var memoryStream = new MemoryStream())
            {
                file.CopyToAsync(memoryStream);
                park.ParkImage = memoryStream.ToArray();
            }

            var result = _context.Update(park);

            if (_context.SaveChanges() == 0)
            {
                return(BadRequest());
            }



            return(Ok());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> PutSlot(int slotId, SlotCreateViewModel model)
        {
            if (slotId == 0)
            {
                return(null);
            }

            var sLot = _context.slots.FirstOrDefault(p => p.SlotId == slotId);

            if (sLot == null)
            {
                return(NotFound());
            }

            sLot.No = model.SlotNo;

            _context.Update(sLot);

            if (_context.SaveChanges() == 0)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Exemplo n.º 13
0
        public AppUser AddNewUser(string provider, List <Claim> claims)
        {
            var appUser = new AppUser();

            appUser.Provider       = provider;
            appUser.NameIdentifier = claims.GetClaim(ClaimTypes.NameIdentifier);
            appUser.Username       = claims.GetClaim("username");
            appUser.Firstname      = claims.GetClaim(ClaimTypes.GivenName);
            appUser.Lastname       = claims.GetClaim(ClaimTypes.Surname);
            var name = claims.GetClaim("name");

            // very rudimentary handling of splitting a users fullname into first and last name. Not very robust.
            if (string.IsNullOrEmpty(appUser.Firstname))
            {
                appUser.Firstname = name?.Split(' ').First();
            }
            if (string.IsNullOrEmpty(appUser.Lastname))
            {
                var nameSplit = name?.Split(' ');
                if (nameSplit.Length > 1)
                {
                    appUser.Lastname = name?.Split(' ').Last();
                }
            }
            appUser.Email  = claims.GetClaim(ClaimTypes.Email);
            appUser.Mobile = claims.GetClaim(ClaimTypes.MobilePhone);
            appUser.Roles  = "NewUser";
            var entity = _context.AppUsers.Add(appUser);

            _context.SaveChanges();
            return(entity.Entity);
        }
Exemplo n.º 14
0
        public User Register(RegistrationModel model, string asRole)
        {
            var userRole = _roleRepository.Get(asRole);

            var salt = new byte[512 / 8];

            _cryptoServiceProvider.GetNonZeroBytes(salt);

            var hashedPass = GetHashedPassword(model.Password, salt);

            var user = new User
            {
                Username       = model.Username,
                Email          = model.Email,
                Salt           = salt,
                HashedPassword = hashedPass,
                Roles          = new List <Role> {
                    userRole
                }
            };

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

            return(user);
        }
Exemplo n.º 15
0
 public void AuthDbContextTest()
 {
     using (var context = new AuthDbContext())
     {
         context.SaveChanges();
     }
 }
Exemplo n.º 16
0
        public void CreateUserAsync(UserDto user)
        {
            var usertomap = mapper.Map <User>(user);

            context.Users.Add(usertomap);
            context.SaveChanges();
        }
Exemplo n.º 17
0
        public void Create(User user)
        {
            try
            {
                user.Password = Crypto.EncryptPassword(user.Password);

                Ctx.Users.Add(user);
                Ctx.SaveChanges();

                Logger.LogInformation($"Salvando usuário -> {user.UserId}");
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                throw;
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// initializing Acl tables, remove after using
        /// for using in Hillavas.BaseProject_MaterialPro.Data.Migrations.Configuration.cs
        /// just add "AclSeed.Init(context);" to seed method
        /// </summary>
        /// <param name="db">project context</param>
        public bool Init()
        {
            using (var bt = _db.Database.BeginTransaction())
            {
                var rep = AddAdminUserAndRole();
                if (!rep.Success)
                {
                    return(false);
                }

                #region UserInRole
                var userInRole = new UserInRole()
                {
                    UserId = rep.UserId,
                    RoleId = rep.RoleId
                };
                _db.Set <UserInRole>().Add(userInRole);

                if (_db.SaveChanges() == 0)
                {
                    bt.Rollback();
                    return(false);
                }
                #endregion

                var actionsRep = AddActions();
                if (!actionsRep.Success)
                {
                    bt.Rollback();
                    return(false);
                }
                _db.Set <ActionInRole>().AddRange(actionsRep.actions.Select(x => new ActionInRole
                {
                    RoleId    = rep.RoleId,
                    ActionId  = x.ActionId,
                    IsDefault = x.ActionName == "ProfileInfo" ? true : false
                }));
                if (_db.SaveChanges() == 0)
                {
                    bt.Rollback();
                    return(false);
                }
                bt.Commit();
                return(true);
            }
        }
Exemplo n.º 19
0
        private static void UpdateAdminPermissions(AuthDbContext dbContext)
        {
            // making sure the admin have all permissions after each deploy
            var dbContextPermissions = dbContext.Permissions.Where(x => x.UserId == 1).ToList();

            dbContext.Permissions.RemoveRange(dbContextPermissions);
            dbContext.SaveChanges();
            var allPermissions = Enum.GetValues(typeof(UserPermission)).Cast <UserPermission>()
                                 .Select(p => new Permission
            {
                UserPermission = p,
                UserId         = 1
            });

            dbContext.Permissions.AddRange(allPermissions);
            dbContext.SaveChanges();
        }
Exemplo n.º 20
0
        public static void Initialize(IApplicationBuilder app, AuthDbContext context)
        {
            context.Database.EnsureCreated();

            InitializeTokenServerConfigurationDatabase(app);

            context.SaveChanges();
        }
Exemplo n.º 21
0
        public static void Seed(this AuthDbContext dbContext)
        {
            dbContext.Products.Add(new Models.Product
            {
                Name         = "Name1",
                LatinName    = "LatinName1",
                Description  = "Description1",
                Kind         = "Kind1",
                Type         = "Type1",
                Light        = "Light1",
                Water        = "Water1",
                ProductDate  = DateTime.Now,
                Picture      = null,
                PictureTwo   = null,
                PictureThree = null,
                Trade        = "Trade1",
                Delivery     = "Delivery1",
                Soil         = "Soil1"
            });

            dbContext.Products.Add(new Models.Product
            {
                Name         = "Name2",
                LatinName    = "LatinName2",
                Description  = "Description2",
                Kind         = "Kind2",
                Type         = "Type2",
                Light        = "Light2",
                Water        = "Water2",
                ProductDate  = DateTime.Now,
                Picture      = null,
                PictureTwo   = null,
                PictureThree = null,
                Trade        = "Trade2",
                Delivery     = "Delivery2",
                Soil         = "Soil2"
            });

            dbContext.Products.Add(new Models.Product
            {
                Name         = "Name3",
                LatinName    = "LatinName3",
                Description  = "Description3",
                Kind         = "Kind3",
                Type         = "Type3",
                Light        = "Light3",
                Water        = "Water3",
                ProductDate  = DateTime.Now,
                Picture      = null,
                PictureTwo   = null,
                PictureThree = null,
                Trade        = "Trade3",
                Delivery     = "Delivery3",
                Soil         = "Soil3"
            });

            dbContext.SaveChanges();
        }
Exemplo n.º 22
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
Exemplo n.º 23
0
        public void UpdateAccount(Account account)
        {
            using (var context = new AuthDbContext())
            {
                context.Entry(account).State = EntityState.Modified;

                context.SaveChanges();
            }
        }
Exemplo n.º 24
0
        //database relationships
        public TermGrade InitializeGrades(string term)
        {
            var termGrade = new TermGrade
            {
                Term  = term,
                Grade = 0
            };

            string[] types = { "Quiz1", "Quiz2", "Quiz3", "Assignment1", "Assignment2", "Assignment3" };

            var item = new QuizOrAssignment();

            for (int i = 0; i < types.Length; i++)
            {
                item = new QuizOrAssignment
                {
                    Grade = 0,
                    Type  = types[i]
                };

                authDbContext.Add(item);
                authDbContext.SaveChanges();

                switch (i)
                {
                case 0:
                    termGrade.Quiz1ID = item.ID;
                    break;

                case 1:
                    termGrade.Quiz2ID = item.ID;
                    break;

                case 2:
                    termGrade.Quiz3ID = item.ID;
                    break;

                case 3:
                    termGrade.Assignment1ID = item.ID;
                    break;

                case 4:
                    termGrade.Assignment2ID = item.ID;
                    break;

                case 5:
                    termGrade.Assignment3ID = item.ID;
                    break;

                default:
                    break;
                }
            }

            return(termGrade);
        }
        public bool CreateUser(User user)
        {
            var createdUser = _context.Add(user);

            if (_context.SaveChanges() > 0)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 26
0
 public ActionResult Register(AppUser user)
 {
     if (ModelState.IsValid)
     {
         db.AppUsers.Add(user);
         db.SaveChanges();
         return(RedirectToAction("Login", "Accounts"));
     }
     return(View());
 }
Exemplo n.º 27
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Exemplo n.º 28
0
        public IActionResult Create(Song song)
        {
            try
            {
                List <String> listExt = new List <String>()
                {
                    "mp3", "wav", "m4a", "flac", "mp4", "wma", "aac"
                };
                var Files = Request.Form.Files;

                foreach (var file in Files)
                {
                    var songs = Path.Combine(hostingEnvironment.WebRootPath, "songs");
                    if (file.Length > 0)
                    {
                        string filename     = Guid.NewGuid().ToString();
                        var    old_filename = file.FileName.Split('.');
                        var    extension    = old_filename.Last().ToLower();

                        if (listExt.Contains(extension) == false)
                        {
                            ViewData["error_file_type"] = "You have send a non authorized type file";
                            return(View());
                        }

                        song.PathFileSong = filename + "." + extension;
                        using (var fileStream = new FileStream(Path.Combine(songs, song.PathFileSong), FileMode.Create))
                        {
                            file.CopyTo(fileStream);
                        }
                        _context.Add(song);
                        _context.SaveChanges();
                    }
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 29
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);

            _context.SaveChanges();
        }
Exemplo n.º 30
0
        public IActionResult GetUnreservedSlot(int id)
        {
            ReservationHistoryViewModel model = new ReservationHistoryViewModel();

            if (id == 0)
            {
            }

            var slotreservation = _context.slotReservations.Include(p => p.slot).Include(p => p.slot.Parking)
                                  .FirstOrDefault(p => p.SlotReservationId == id && p.slot.Reserved == true);

            if (slotreservation != null)
            {
                slotreservation.ReservationEndTime = DateTime.Now;

                _context.Update(slotreservation);
                _context.SaveChanges();
            }



            var slot = _context.slots.FirstOrDefault(p => p.SlotId == slotreservation.slot.SlotId);

            if (slot != null)
            {
                slot.Reserved = false;
                _context.Update(slot);
                _context.SaveChanges();
            }


            model.Id              = slotreservation.SlotReservationId;
            model.No              = slotreservation.slot.SlotId;
            model.Parking         = slotreservation.slot.Parking.Name;
            model.ReservationTime = slotreservation.ReservationTime.ToString();
            model.EndTime         = slotreservation.ReservationEndTime.ToString();
            model.City            = slotreservation.slot.Parking.City;


            return(new OkObjectResult(model));
        }