public async Task <ActionResult <VoteOption> > Post(VoteOption voteOption)
        {
            if (voteOption == null)
            {
                return(BadRequest());
            }

            db.VoteOptions.Add(voteOption);
            await db.SaveChangesAsync();

            return(Ok(voteOption));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutAfschrijving([FromRoute] int id, [FromBody] AfschrijvingPostModel afschrijvingPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != afschrijvingPM.Id)
            {
                return(BadRequest());
            }

            Afschrijving afschrijving = _context.Afschrijving.Where(a => a.Id == id).Include(a => a.AfschrijvingLabels).First();

            afschrijving.LaatstGewijzigd     = DateTime.Now;
            afschrijving.Aankoopbedrag       = afschrijvingPM.Aankoopbedrag;
            afschrijving.Aankoopdatum        = afschrijvingPM.Aankoopdatum;
            afschrijving.VerwachteLevensduur = afschrijvingPM.VerwachteLevensduur;
            afschrijving.Garantie            = afschrijvingPM.Garantie;
            afschrijving.Factuur             = afschrijvingPM.Factuur;
            afschrijving.FactuurNaam         = afschrijvingPM.FactuurNaam;

            afschrijving.AfschrijvingLabels.Clear();

            foreach (var newLabelId in afschrijvingPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                afschrijving.AfschrijvingLabels.Add
                (
                    nieuwAfschrijvingLabel(afschrijving, label)
                );
            }

            _context.Entry(afschrijving).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AfschrijvingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <User> > Post(Class _class)
        {
            if (_class == null)
            {
                return(BadRequest());
            }

            db.Classes.Add(_class);
            await db.SaveChangesAsync();

            return(Ok(_class));
        }
Esempio n. 4
0
        public async Task <ActionResult <UserEventDocument> > Post(UserEventDocument userEventDocument)
        {
            if (userEventDocument == null)
            {
                return(BadRequest());
            }

            db.UserEventDocuments.Add(userEventDocument);
            await db.SaveChangesAsync();

            return(Ok(userEventDocument));
        }
Esempio n. 5
0
        public async Task <IActionResult> PutInkomst([FromRoute] int id, [FromBody] InkomstPostModel inkomstVM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != inkomstVM.Id)
            {
                return(BadRequest());
            }

            Inkomst inkomst = _context.Inkomst.Where(i => i.Id == id).Include(i => i.InkomstLabels).First();

            inkomst.Persoon         = inkomstVM.Persoon;
            inkomst.Bedrag          = inkomstVM.Bedrag;
            inkomst.Begindatum      = inkomstVM.Begindatum;
            inkomst.Einddatum       = inkomstVM.Einddatum;
            inkomst.Interval        = inkomstVM.Interval;
            inkomst.LaatstGewijzigd = DateTime.Now;

            inkomst.InkomstLabels.Clear();

            foreach (var newLabelId in inkomstVM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                inkomst.InkomstLabels.Add
                (
                    nieuwInkomstLabel(inkomst, label)
                );
            }

            _context.Entry(inkomst).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InkomstExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 6
0
        public async Task <IActionResult> PutSpaardoel([FromRoute] int id, [FromBody] SpaardoelPostModel spaardoelPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != spaardoelPM.Id)
            {
                return(BadRequest());
            }

            Spaardoel spaardoel = _context.Spaardoel.Where(r => r.Id == id).Include(r => r.SpaardoelLabels).First();

            spaardoel.Percentage      = spaardoelPM.Percentage;
            spaardoel.Eindbedrag      = spaardoelPM.Eindbedrag;
            spaardoel.EersteMaand     = spaardoelPM.EersteMaand;
            spaardoel.LaatsteMaand    = spaardoelPM.LaatsteMaand;
            spaardoel.Omschrijving    = spaardoelPM.Omschrijving;
            spaardoel.LaatstGewijzigd = DateTime.Now;

            spaardoel.SpaardoelLabels.Clear();

            foreach (var newLabelId in spaardoelPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                spaardoel.SpaardoelLabels.Add
                (
                    nieuwSpaardoelLabel(spaardoel, label)
                );
            }

            _context.Entry(spaardoel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpaardoelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 7
0
        public async Task <IActionResult> PutBudget([FromRoute] int id, [FromBody] BudgetPostModel budgetPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != budgetPM.Id)
            {
                return(BadRequest());
            }

            Budget budget = _context.Budget.Where(i => i.Id == id).Include(i => i.BudgetLabels).First();

            budget.Bedrag          = budgetPM.Bedrag;
            budget.Begindatum      = budgetPM.Begindatum;
            budget.Einddatum       = budgetPM.Einddatum;
            budget.Interval        = budgetPM.Interval;
            budget.LaatstGewijzigd = DateTime.Now;

            budget.BudgetLabels.Clear();

            foreach (var newLabelId in budgetPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                budget.BudgetLabels.Add
                (
                    nieuwBudgetLabel(budget, label)
                );
            }

            _context.Entry(budget).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BudgetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 8
0
        public async Task <IActionResult> PutReservering([FromRoute] int id, [FromBody] ReserveringPostModel reserveringPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != reserveringPM.Id)
            {
                return(BadRequest());
            }

            Reservering reservering = _context.Reservering.Where(r => r.Id == id).Include(r => r.ReserveringLabels).First();

            reservering.Bedrag          = reserveringPM.Bedrag;
            reservering.Maand           = reserveringPM.Maand;
            reservering.Omschrijving    = reserveringPM.Omschrijving;
            reservering.LaatstGewijzigd = DateTime.Now;

            reservering.ReserveringLabels.Clear();

            foreach (var newLabelId in reserveringPM.Label)
            {
                Label label = _context.Label.Where(l => l.Id == newLabelId).First();
                reservering.ReserveringLabels.Add
                (
                    nieuwReserveringLabel(reservering, label)
                );
            }

            _context.Entry(reservering).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReserveringExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 9
0
        public async Task <ActionResult> Create([Bind(Include = "Id,OrderId,ItemId,Quantity")] OrderItem orderItem)
        {
            if (ModelState.IsValid)
            {
                db.OrderItems.Add(orderItem);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.ItemId  = new SelectList(db.Items, "Id", "Name", orderItem.ItemId);
            ViewBag.OrderId = new SelectList(db.Orders, "Id", "OrderNo", orderItem.OrderId);
            return(View(orderItem));
        }
Esempio n. 10
0
        public async Task <ActionResult <New> > Post(New _new)
        {
            User user = db.Users.FirstOrDefault(p => p.Login == User.Identity.Name);

            if (_new == null)
            {
                return(BadRequest());
            }
            _new.AuthorId = user.Id;
            db.News.Add(_new);
            await db.SaveChangesAsync();

            return(Ok(_new));
        }
Esempio n. 11
0
        public async Task <ActionResult <Vote> > Post(Vote vote)
        {
            if (vote == null)
            {
                return(BadRequest());
            }
            User user = db.Users.FirstOrDefault(p => p.Login == User.Identity.Name);

            vote.AuthorId = user.Id;
            db.Votes.Add(vote);
            await db.SaveChangesAsync();

            return(Ok(vote));
        }
Esempio n. 12
0
        public async Task <IActionResult> OnPost(IFormFile image, IFormFile template, string guid, string title, string keywords, string description)
        {
            Template temp = this.context.Set <Template>().Where(t => t.DocumentLink.Equals(guid)).FirstOrDefault();

            if (temp == null)
            {
                return(Redirect("/templates"));
            }

            string toDeleteImage = null, toDeleteDocument = null;

            if (image != null)
            {
                LocalFile localFile = LocalFile.Create(image);
                await azureFileController.UploadFile(FileType.Images, localFile.LocalPath, localFile.Stream);

                toDeleteImage         = temp.PreviewImageLink;
                temp.PreviewImageLink = Path.GetFileName(localFile.LocalPath);
            }

            if (template != null)
            {
                LocalFile localFile = LocalFile.Create(template);
                await azureFileController.UploadFile(FileType.Templates, localFile.LocalPath, localFile.Stream);

                toDeleteDocument  = temp.DocumentLink;
                temp.DocumentLink = Path.GetFileName(localFile.LocalPath);
            }

            temp.Title       = title;
            temp.Description = description;
            temp.Keywords    = keywords;
            await context.SaveChangesAsync();

            if (!string.IsNullOrEmpty(toDeleteDocument))
            {
                try
                {
                    await azureFileController.DeleteFile(FileType.Templates, toDeleteDocument);
                } catch (Exception e) {
                    System.Diagnostics.Trace.TraceError(string.Format("Deleting old Document failed. Guid: {0}. Stack: {1}", toDeleteDocument, e.StackTrace));
                }
            }

            if (!string.IsNullOrEmpty(toDeleteImage))
            {
                try
                {
                    await azureFileController.DeleteFile(FileType.Images, toDeleteImage);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.TraceError(string.Format("Deleting old Image failed. Guid: {0}. Stack: {1}", toDeleteImage, e.StackTrace));
                }
            }

            return(OnGet(temp.ID.ToString()));
        }
Esempio n. 13
0
        public async Task <ActionResult <Event> > Post(Event _event)
        {
            User user = db.Users.FirstOrDefault(p => p.Login == User.Identity.Name);

            if (_event == null)
            {
                return(BadRequest());
            }

            if (_event.AuthorId == 0)
            {
                _event.AuthorId = user.Id;
            }
            db.Events.Add(_event);
            await db.SaveChangesAsync();

            return(Ok(_event));
        }
Esempio n. 14
0
        public async Task <IActionResult> PutRekening([FromRoute] int id, [FromBody] RekeningPostModel rekeningPM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != rekeningPM.Id)
            {
                return(BadRequest());
            }

            Rekening rekening = _context.Rekening.Where(a => a.Id == id).First();

            rekening.LaatstGewijzigd = DateTime.Now;
            rekening.Naam            = rekeningPM.Naam;
            rekening.Iban            = rekeningPM.Iban;
            rekening.Hoofdrekening   = rekeningPM.Hoofdrekening;
            rekening.Startbedrag     = rekeningPM.Startbedrag;

            _context.Entry(rekening).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RekeningExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 15
0
        public async Task <IActionResult> DeleteMessage(int id)
        {
            Message message = _db.Messages.FirstOrDefault(m => m.Id == id);

            if (message != null)
            {
                _db.Messages.Remove(message);
                await _db.SaveChangesAsync();

                return(Redirect($"~/Messages/ViewMyMessages/{message.UserId}"));
            }

            return(Redirect($"~/Home/Index"));
        }
        public async Task <int> SaveNewUser(RegisterModel register)
        {
            var boolResponse = CheckUserExistsOrNot(register.Email);

            if (boolResponse.Result == true)
            {
                return(intResponse = 0);
            }
            else
            {
                _dbContext.Add(register);
                intResponse = await _dbContext.SaveChangesAsync();

                return(intResponse);
            }
        }
Esempio n. 17
0
        Task IUserRoleStore <AppUser> .AddToRoleAsync(AppUser user, string roleName, CancellationToken cancellationToken)
        {
            //throw new NotImplementedException();
            var          userId                = user.Id;
            IdentityRole role                  = _roleManager.FindByNameAsync(roleName).Result;
            var          roleIdResult          = _roleManager.GetRoleIdAsync(role);
            IdentityUserRole <string> userRole = new IdentityUserRole <string>
            {
                RoleId = roleIdResult.Result,
                UserId = userId
            };

            Context.UserRoles.Add(userRole);
            Context.SaveChangesAsync();

            return(Task.FromResult(IdentityResult.Success));
        }
Esempio n. 18
0
        public async Task <ActionResult> OnPostFavorite(string id, string query)
        {
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }

            this.CurrentUser = context.Set <Models.User>().Where(entry => entry.Email.Equals(userEmail)).FirstOrDefault();
            if (this.CurrentUser == null)
            {
                return(Redirect("~/login"));
            }
            else
            {
                context.Entry(this.CurrentUser).Collection(u => u.Favorites).Load();
                if (this.CurrentUser.Favorites.Any(fav => fav.TemplateId.Equals(new Guid(id))))
                {
                    // remove it
                    this.CurrentUser.Favorites = this.CurrentUser.Favorites.Where(fav => !fav.TemplateId.Equals(new Guid(id))).ToList();
                    context.Update(this.CurrentUser);
                }
                else
                {
                    // add it
                    this.CurrentUser.Favorites.Add(new Favourite()
                    {
                        TemplateId = new Guid(id),
                        UserId     = this.CurrentUser.ID
                    });
                }

                await context.SaveChangesAsync();

                return(OnGet(id, query));
            }
        }
        public async Task <ActionResult> OnPostDelete(string template)
        {
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }
            else
            {
                this.CurrentUser = _context.Set <Models.User>().Where(entry => entry.Email.Equals(userEmail)).FirstOrDefault();
                _context.Entry(this.CurrentUser).Collection(u => u.Favorites).Load();

                Favourite t = this.CurrentUser.Favorites.FirstOrDefault(fav => fav.TemplateId.Equals(new Guid(template)));

                if (t != null)
                {
                    _context.Remove(t);
                    await _context.SaveChangesAsync();
                }
                return(Page());
            }
        }
Esempio n. 20
0
        public async Task <IActionResult> DeleteBackup([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var backup = await _context.BackupOverzicht.FindAsync(id);

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

            var fileName = new SqlParameter("@FileName", backup.Bestandsnaam);

            _context.Database.ExecuteSqlCommand("EXEC dbo.[DeleteBackup] @FileName", fileName);

            _context.BackupOverzicht.Remove(backup);
            await _context.SaveChangesAsync();

            return(Ok(backup));
        }
Esempio n. 21
0
        public async Task <IActionResult> OnGet(string email, string guid)
        {
            if (!string.IsNullOrEmpty(HttpContext.User.Identity.Name))
            {
                return(Redirect("/Home"));
            }

            Models.User user = _context.Set <Models.User>().Where(entry => entry.Email.Equals(email)).FirstOrDefault();

            if (user != null && user.VerifyString.Equals(new Guid(guid)))
            {
                user.Verified = true;
                _context.Update(user);
                await _context.SaveChangesAsync();

                return(RedirectToPage("/user/login"));
            }
            else
            {
                // TODO make bad page
                return(RedirectToPage(""));
            }
        }
Esempio n. 22
0
        public async Task <ActionResult <User> > Profile(User _user)
        {
            User user = await db.Users.FirstOrDefaultAsync(p => p.Login == User.Identity.Name);

            user.Firstname = _user.Firstname;
            user.Surname   = _user.Surname;
            user.Email     = _user.Email;
            user.Phone     = _user.Phone;
            db.Update(user);
            await db.SaveChangesAsync();

            return(new ObjectResult(_user));
        }
        public async Task CreateAsync(T entity)
        {
            await Context.Set <T>().AddAsync(entity);

            await Context.SaveChangesAsync();
        }
        public async Task <ActionResult> OnPost(UserChangeRequest changeRequest)
        {
            this.Success = string.Empty;
            this.Error   = string.Empty;
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }

            this.CurrentUser = context.Set <Models.User>().Where(entry => entry.Email.Equals(userEmail)).FirstOrDefault();
            if (this.CurrentUser == null)
            {
                return(Redirect("~/login"));
            }
            else
            {
                context.Entry(this.CurrentUser).Collection(u => u.UserInfo).Load();

                string res = string.Empty;

                if (!string.IsNullOrEmpty(changeRequest.AltEmail) && !DataValidator.Email(changeRequest.AltEmail, out res))
                {
                    this.Error = res;
                    return(Page());
                }

                if (!DataValidator.FirstName(changeRequest.FirstName, out res))
                {
                    this.Error = res;
                    return(Page());
                }

                if (!DataValidator.LastName(changeRequest.LastName, out res))
                {
                    this.Error = res;
                    return(Page());
                }

                if (!string.IsNullOrEmpty(changeRequest.Phone) && !DataValidator.PhoneNumber(changeRequest.Phone, out res))
                {
                    this.Error = res;
                    return(Page());
                }

                if (!string.IsNullOrEmpty(changeRequest.Web) && !DataValidator.Website(changeRequest.Web, out res))
                {
                    this.Error = res;
                    return(Page());
                }

                if (!string.IsNullOrEmpty(changeRequest.NewPassword))
                {
                    if (!DataValidator.Password(changeRequest.NewPassword, out res))
                    {
                        this.Error = res;
                        return(Page());
                    }

                    if (PasswordHelper.Check(this.CurrentUser, changeRequest.OldPassword))
                    {
                        this.CurrentUser.PasswordHash = PasswordHelper.Hash(changeRequest.NewPassword);
                    }
                    else
                    {
                        this.Error = "Old password provided is not correct.";
                        return(Page());
                    }
                }

                this.CurrentUser.FirstName = changeRequest.FirstName;
                this.CurrentUser.LastName  = changeRequest.LastName;

                if (!this.CurrentUser.UserInfo.Any())
                {
                    UserInfo info = new UserInfo()
                    {
                        Id          = Guid.NewGuid(),
                        UserId      = this.CurrentUser.ID,
                        AltEmail    = changeRequest.AltEmail,
                        NameExt     = changeRequest.NameExt,
                        PhoneNumber = changeRequest.Phone,
                        Summary     = changeRequest.Summary,
                        Website     = changeRequest.Web
                    };

                    this.CurrentUser.UserInfo.Add(info);
                }
                else
                {
                    this.CurrentUser.UserInfo.First().AltEmail    = changeRequest.AltEmail;
                    this.CurrentUser.UserInfo.First().NameExt     = changeRequest.NameExt;
                    this.CurrentUser.UserInfo.First().PhoneNumber = changeRequest.Phone;
                    this.CurrentUser.UserInfo.First().Summary     = changeRequest.Summary;
                    this.CurrentUser.UserInfo.First().Website     = changeRequest.Web;
                }

                this.Success = "Changes have been save successfully.";
                await context.SaveChangesAsync();

                return(Page());
            }
        }
Esempio n. 25
0
        public async Task <IActionResult> OnPost(IFormFile image, IFormFile template, string title, string keywords, string description)
        {
            string userEmail = this.HttpContext.User.Identity.Name;

            if (string.IsNullOrEmpty(userEmail))
            {
                return(Redirect("~/login"));
            }

            this.CurrentUser = _context.Set <User>().Where(entry => entry.Email.Equals(userEmail)).FirstOrDefault();
            if (this.CurrentUser == null)
            {
                return(Redirect("~/login"));
            }
            else
            {
                if (!acceptableImageExtensions.Contains(Path.GetExtension(image.FileName)))
                {
                    this.Error = "Only JPG and PNG images can be uploaded at this time.";
                    return(Page());
                }

                if (!acceptableTemplateExtensions.Contains(Path.GetExtension(template.FileName)))
                {
                    this.Error = "Only DOCX files can be uploaded at this time.";
                    return(Page());
                }

                Template toAdd = new Template()
                {
                    UploadDate  = DateTime.UtcNow,
                    Title       = title,
                    UserID      = this.CurrentUser.ID,
                    Keywords    = keywords,
                    Description = description
                };

                LocalFile localFile = LocalFile.Create(template);
                try
                {
                    await azureFileController.UploadFile(FileType.Templates, localFile.LocalPath, localFile.Stream);
                }
                catch (Exception e)
                {
                    this.Error = "Something bad happened during uploading... Please try again later.";
                    System.Diagnostics.Trace.TraceError("Error during uploading:" + e.ToString());
                    await azureFileController.DeleteFile(FileType.Templates, Path.GetFileName(localFile.LocalPath));

                    return(Page());
                }
                toAdd.DocumentLink = Path.GetFileName(localFile.LocalPath);

                LocalFile localFile2 = LocalFile.Create(image);
                try
                {
                    await azureFileController.UploadFile(FileType.Images, localFile2.LocalPath, localFile2.Stream);
                }
                catch (Exception e)
                {
                    this.Error = "Something bad happened during uploading... Please try again later.";
                    System.Diagnostics.Trace.TraceError("Error during uploading:" + e.ToString());

                    // won't save record, need to clean up AzureFileStorage
                    await azureFileController.DeleteFile(FileType.Images, Path.GetFileName(localFile2.LocalPath));

                    await azureFileController.DeleteFile(FileType.Templates, toAdd.DocumentLink);

                    return(Page());
                }
                toAdd.PreviewImageLink = Path.GetFileName(localFile2.LocalPath);

                this.CurrentUser.Templates.Add(toAdd);
                _context.SaveChangesAsync().Wait();

                return(Redirect("~/templates"));
            }
        }