public IActionResult Edit(MuseumVM model)
        {
            if (!ModelState.IsValid)
            {
                model.MuseumTypes = new SelectList(museumTypeRepository.GetMuseumTypes(), "Id", "Name");
                return(View("Edit", model));
            }

            Museums m = new Museums();

            m.Id            = model.Id;
            m.Name          = model.Name;
            m.UserId        = model.UserId;
            m.Latitude      = model.Latitude;
            m.Longitude     = model.Longitude;
            m.Address       = model.Address;
            m.Email         = model.Email;
            m.Phone         = model.Phone;
            m.MuseumTypeId  = model.MuseumTypeId;
            m.Description   = model.Description;
            m.OpeningYear   = model.Year;
            m.QrScanning    = model.QrScanning;
            m.OnlineTickets = model.TicketSelling;

            museumRepository.UpdateMuseum(m);
            museumRepository.Save();

            return(RedirectToAction("Details", new { id = model.Id }));
        }
示例#2
0
        public IActionResult Edit(MuseumVM museum)
        {
            if (!ModelState.IsValid)
            {
                museum.MuseumType = new SelectList(museumtypeRepository.GetMuseumTypes(), "Id", "Name").ToList();
                return(View("Edit", museum));
            }

            UserAccounts u = userRepository.GetUserById(museum.UserId);

            if (museum.PasswordHash != null && museum.PasswordSalt != null)
            {
                if (museum.NewPassword == museum.RepeatPassword)
                {
                    if (museum.NewPassword != null && museum.RepeatPassword != null)
                    {
                        string password = museum.NewPassword;
                        u.PasswordSalt = GeneratePassword.GenerateSalt();
                        u.PasswordHash = GeneratePassword.GenerateHash(password, u.PasswordSalt);
                    }
                    else
                    {
                        u.PasswordHash = museum.PasswordHash;
                        u.PasswordSalt = museum.PasswordSalt;
                    }
                    u.Username = museum.Username;
                    userRepository.UpdateUser(u);
                    museumRepository.Save();

                    Museums m = museumRepository.GetMuseum(museum.Id);
                    m.MuseumTypeId = museum.MuseumTypeId;
                    m.Name         = museum.Name;
                    m.UserId       = u.Id;

                    museumRepository.UpdateMuseum(m);
                    museumRepository.Save();
                }
            }
            return(RedirectToAction("Index"));
        }