Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,userSenderId,organizationReceiverId,amount")] Payment payment)
        {
            if (id != payment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(payment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentExists(payment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(payment));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,name,description,actionType,organizationId,creationDateTime,startDateTime,endDateTime")] CharityAction charityAction, string loggedOrg = null)
        {
            if (loggedOrg == null)
            {
                if (HttpContext.Session.GetString("username") == null)
                {
                    return(RedirectToAction("", ""));
                }
            }
            if (ModelState.IsValid)
            {
                string orgId = loggedOrg;
                if (orgId == null)
                {
                    orgId = HttpContext.Session.GetString("idOfLoggedAccount");
                }
                charityAction.organizationId   = Guid.Parse(orgId);
                charityAction.creationDateTime = DateTime.Now;

                charityAction.Id = Guid.NewGuid();
                _context.Add(charityAction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(charityAction));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,firstName,lastName,gender,dateOfBirth")] User user)
        {
            Guid idOfLoggedAccount = Guid.Parse(HttpContext.Session.GetString("idOfLoggedUserAccount"));

            //user.Id = id;
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    user.UserAccount = idOfLoggedAccount;

                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> CreateUserAccount([Bind("Id, username, password, email")] Account account, string userFirstNameParam = null)
        {
            if (ModelState.IsValid)
            {
                if (!UsernameExists(account.username))
                {
                    account.Id     = Guid.NewGuid();
                    account.isUser = true;
                    var sha256 = SHA256.Create();
                    var pass1  = sha256.ComputeHash(Encoding.UTF8.GetBytes(account.password));
                    var hash1  = BitConverter.ToString(pass1).Replace("-", "").ToLower();
                    account.password = hash1;
                    _context.Add(account);
                    User user = null;
                    if (userFirstNameParam == null)
                    {
                        string userId          = HttpContext.Session.GetString("registrationId");
                        string userFirstName   = HttpContext.Session.GetString("registrationFirstName");
                        string userLastName    = HttpContext.Session.GetString("registrationLastName");
                        string userGender      = HttpContext.Session.GetString("registrationGender");
                        string userDateOfBirth = HttpContext.Session.GetString("registrationBirthday");

                        user             = new User();
                        user.Id          = Guid.Parse(userId);
                        user.firstName   = userFirstName;
                        user.lastName    = userLastName;
                        user.gender      = Char.Parse(userGender);
                        user.dateOfBirth = DateTime.Parse(userDateOfBirth);

                        HttpContext.Session.Remove("registrationId");
                        HttpContext.Session.Remove("registrationFirstName");
                        HttpContext.Session.Remove("registrationLastName");
                        HttpContext.Session.Remove("registrationGender");
                        HttpContext.Session.Remove("registrationBirthday");
                    }
                    else
                    {
                        user = new User {
                            Id = new Guid(), firstName = "Test", lastName = "Unit", gender = 'F', dateOfBirth = new DateTime(1990, 3, 5)
                        };
                    }
                    user.UserAccount = account.Id;
                    _context.Add <User>(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ModelState.AddModelError("", "Username already exists, please try again.");
                    return(View("~/Views/Accounts/CreateUser.cshtml"));
                }
            }
            return(View(account));
        }
Ejemplo n.º 5
0
        public async Task <bool> LockUserAsync(string id)
        {
            var user = _context.Users.Find(id);

            if (user == null)
            {
                return(false);
            }
            user.LockoutEnabled = true;
            user.LockoutEnd     = DateTime.MaxValue;
            return(await _context.SaveChangesAsync() > 0);
        }
        public async Task <IActionResult> Create([Bind("Id,name,dateOfFounding,description")] Organization organization)
        {
            if (ModelState.IsValid)
            {
                organization.Id = Guid.NewGuid();
                HttpContext.Session.SetString("registrationId", (organization.Id).ToString());
                HttpContext.Session.SetString("registrationName", organization.name);
                HttpContext.Session.SetString("registrationDateOfFounding", organization.dateOfFounding.ToString());
                HttpContext.Session.SetString("registrationDescription", organization.description);
                organization.Id = Guid.NewGuid();
                //_context.Add(organization);
                await _context.SaveChangesAsync();

                return(RedirectToAction("CreateOrganizationAccount", "Account"));
            }
            return(View(organization));
        }
Ejemplo n.º 7
0
        public async Task ConsumeAsync(UserUpdatedEvent message)
        {
            var charitiesToUpdate = _context.Charities.Where(u => u.OwnerUserKey == message.UserKey);

            foreach (var charity in charitiesToUpdate)
            {
                charity.OwnerUserName = Helpers.GetUserName(message);
            }

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,name,description,value,userDonatedId")] Item item, string loggedUser = null)
        {
            if (loggedUser == null)
            {
                if (HttpContext.Session.GetString("username") == null)
                {
                    return(RedirectToAction("", ""));
                }
            }
            if (ModelState.IsValid)
            {
                string userUsername = loggedUser;
                if (loggedUser == null)
                {
                    userUsername = HttpContext.Session.GetString("username");
                }

                var account = await _context.account.FirstOrDefaultAsync(m => m.username == userUsername);

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

                var user = await _context.user.FirstOrDefaultAsync(m => m.UserAccount == account.Id);

                if (user == null)
                {
                    return(NotFound());
                }
                item.Id            = Guid.NewGuid();
                item.userDonatedId = user.Id;
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(item));
        }
        public async Task <IActionResult> Edit(Image image)
        {
            var ourImage = await _context.image.FindAsync(image.Id);

            if (ourImage != null)
            {
                ourImage.Path = image.Path;
            }
            else
            {
                _context.image.Add(image);
            }

            await _context.SaveChangesAsync();

            return(View());
        }
Ejemplo n.º 10
0
 public async Task <bool> CreateAsync(Donation donation)
 {
     _context.Add(donation);
     return(await _context.SaveChangesAsync() > 0);
 }
Ejemplo n.º 11
0
 public async Task <bool> CreateAsync(Category category)
 {
     _context.Category.Add(category);
     return(await _context.SaveChangesAsync() > 0);
 }
Ejemplo n.º 12
0
 public async Task <bool> CreateAsync(Institution institution)
 {
     _context.Institution.Add(institution);
     return(await _context.SaveChangesAsync() > 0);
 }