public async Task <IActionResult> createAnswer(int fkquestion, int fkuser, string answermessage)
        {
            var userid      = HttpContext.Session.GetInt32("userid");
            var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

            if (currentUser == null)
            {
                return(RedirectToAction("customErrorPage", "user"));
            }
            else
            {
                var currentQuestion = await _context.questions.FirstOrDefaultAsync(m => m.id == fkquestion);

                if (currentQuestion == null)
                {
                    return(RedirectToAction("customErrorPage", "user"));
                }
                else
                {
                    cFunding.Models.answer answer = new cFunding.Models.answer();
                    answer.fkquestion      = currentQuestion;
                    answer.fkuser          = currentUser;
                    answer.answermessage   = answermessage;
                    answer.answerdate      = DateTimeOffset.Now;
                    answer.validatedAnswer = false;

                    _context.Add(answer);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> Create([Bind("id,fkuser,sendername,senderemail,mailsubject,mailmessage")] contactus contactus, string sendername, string senderemail, string mailsubject, string mailmessage)
        {
            if (ModelState.IsValid)
            {
                var userid      = HttpContext.Session.GetInt32("userid");
                var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    contactus.fkuser = null;
                }
                else
                {
                    contactus.fkuser      = currentUser;
                    contactus.sendername  = sendername;
                    contactus.senderemail = senderemail;
                    contactus.mailsubject = mailsubject;
                    contactus.mailmessage = mailmessage;

                    _context.Add(contactus);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> Create(int userid, string sendername, string senderemail, string mailsubject, string mailmessage)
        {
            contactus contactus = new contactus();

            if (ModelState.IsValid)
            {
                var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    return(NotFound());
                }
                else
                {
                    contactus.fkuser      = currentUser;
                    contactus.sendername  = sendername;
                    contactus.senderemail = senderemail;
                    contactus.mailsubject = mailsubject;
                    contactus.mailmessage = mailmessage;

                    _context.Add(contactus);
                    await _context.SaveChangesAsync();

                    return(Redirect("http://149.202.210.119:8080/"));
                }
            }
            return(Redirect("http://149.202.210.119:8080/"));
        }
예제 #4
0
        public async Task <IActionResult> createFavorite(int userid, int projectid)
        {
            favorite favorite = new favorite();

            if (ModelState.IsValid)
            {
                var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    return(NotFound());
                }
                else
                {
                    var currentProject = await _context.projects.FirstOrDefaultAsync(m => m.id == projectid);

                    if (currentProject == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        favorite.fkproject = currentProject;
                        favorite.fkuser    = currentUser;


                        _context.Add(favorite);
                        await _context.SaveChangesAsync();

                        return(Json(favorite));
                    }
                }
            }
            return(Json(favorite));
        }
        public async Task <IActionResult> Create([Bind("id,fkquestion,fkuser,answermessage, answerdate")] answer answer, int fkquestion, string answermessage)
        {
            if (ModelState.IsValid)
            {
                var userid      = HttpContext.Session.GetInt32("userid");
                var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    return(RedirectToAction("customErrorPage", "user"));
                }
                else
                {
                    var currentQuestion = await _context.questions.FirstOrDefaultAsync(m => m.id == fkquestion);

                    if (currentQuestion == null)
                    {
                        return(RedirectToAction("customErrorPage", "user"));
                    }
                    else
                    {
                        answer.fkquestion = currentQuestion;
                        answer.fkuser     = currentUser;


                        _context.Add(answer);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> Create([Bind("id,fkuser,fkproject")] favorite favorite, int fkuser, int fkproject)
        {
            if (ModelState.IsValid)
            {
                var userid      = HttpContext.Session.GetInt32("userid");
                var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    return(RedirectToAction("customErrorPage", "user"));
                }
                else
                {
                    var currentProject = await _context.projects.FirstOrDefaultAsync(m => m.id == fkproject);

                    if (currentProject == null)
                    {
                        return(RedirectToAction("customErrorPage", "user"));
                    }
                    else
                    {
                        favorite.fkproject = currentProject;
                        favorite.fkuser    = currentUser;


                        _context.Add(favorite);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }
            return(View(favorite));
        }
        public async Task <IActionResult> createQuestion(int userid, [Bind("questionmessage")] question question)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    return(NotFound());
                }
                else
                {
                    question.fkuser = currentUser;
                    //.ToString("yyyy-MM-dd' 'HH:mm:ssK")
                    question.questiondate      = DateTimeOffset.Now;
                    question.validatedQuestion = false;

                    _context.Add(question);
                    await _context.SaveChangesAsync();

                    return(Json(question));
                }
            }
            return(Json(question));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("id,userfname,userlname,username,useremail,userpassword,userphoto,userdob,useraddress,usercountry,companyname,companylogo,companydescription,nbshareordinary,sharevalueordinary,descordinary,additionalordinary,nbsharepreferencial,sharevaluepreferencial,descpreferencial,additionalpreferencial,nbsharenonvoting,sharevaluenonvoting,descnonvoting,additionalnonvoting,nbshareredeemable,sharevalueredeemable,descredeemable,additionalredeemable,userassets")] user user, IFormFile fileuserphoto, IFormFile filecompanylogo)
        {
            if (ModelState.IsValid)
            {
                // user photo upload
                if (fileuserphoto == null || fileuserphoto.Length == 0)
                {
                    return(Content("file not selected"));
                }

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileuserphoto.FileName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await fileuserphoto.CopyToAsync(stream);
                }

                user.userphoto = "images/" + fileuserphoto.FileName;


                // company logo photo upload
                if (filecompanylogo == null || filecompanylogo.Length == 0)
                {
                    return(Content("file not selected"));
                }

                var path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", filecompanylogo.FileName);

                using (var stream1 = new FileStream(path1, FileMode.Create))
                {
                    await filecompanylogo.CopyToAsync(stream1);
                }

                user.companylogo = "images/" + filecompanylogo.FileName;

                //usetype=false for a normal user
                user.isadmin = false;

                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
 public async Task<IActionResult> Create([Bind("id,categoryname")] category category)
 {
     if (ModelState.IsValid)
     {
         _context.Add(category);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     return View(category);
 }
예제 #10
0
        public async Task <IActionResult> Create([Bind("id,fkproject,fkuser,amount,transactiondate,accountemail")] transaction transaction)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transaction);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(transaction));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("id,fkuser,questionmessage, questiondate")] question question, string questionmessage)
        {
            if (ModelState.IsValid)
            {
                var userid      = HttpContext.Session.GetInt32("userid");
                var currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    return(RedirectToAction("customErrorPage", "user"));
                }
                else
                {
                    question.fkuser       = currentUser;
                    question.questiondate = DateTimeOffset.Now;

                    _context.Add(question);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #12
0
        public async Task <IActionResult> createAnswer([Bind("answermessage")] answer answer, int questionid, int userid)
        {
            if (ModelState.IsValid)
            {
                List <user> users       = _context.users.ToList();
                var         currentUser = await _context.users.FirstOrDefaultAsync(m => m.id == userid);

                if (currentUser == null)
                {
                    return(NotFound());
                }
                else
                {
                    var currentQuestion = await _context.questions.FirstOrDefaultAsync(m => m.id == questionid);

                    if (currentQuestion == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        answer.fkquestion = currentQuestion;
                        answer.fkuser     = currentUser;
                        //.ToString("yyyy-MM-dd' 'HH:mm:ssK")
                        answer.answerdate = DateTimeOffset.Now;


                        _context.Add(answer);
                        await _context.SaveChangesAsync();

                        return(Redirect("http://149.202.210.119:8080/"));
                    }
                }
            }
            return(Redirect("http://149.202.210.119:8080/"));
        }
예제 #13
0
        public async Task<IActionResult> register([Bind("useremail,userpassword")] user user)
        {
            if (ModelState.IsValid)
            {
                user.userfname = null; 
                user.userlname = null; 
                user.username = null; 
                user.userphoto = "images/avatar.jpg"; 
                user.userdob = DateTimeOffset.Now; 
                user.useraddress = null;
                user.usercountry = null;
                user.companyname = null; 
                user.companylogo = "images/noImageAvailable.jpg"; 
                user.companydescription = null; 
                user.nbshareordinary = 0;
                user.sharevalueordinary = 0;
                user.descordinary = null;
                user.additionalordinary = null;
                user.nbsharepreferencial = 0;
                user.sharevaluepreferencial = 0;
                user.descpreferencial = null;
                user.additionalpreferencial = null;
                user.nbsharenonvoting = 0;
                user.sharevaluenonvoting = 0;
                user.descnonvoting = null;
                user.additionalnonvoting = null;
                user.nbshareredeemable = 0;
                user.sharevalueredeemable = 0;
                user.descredeemable = null;
                user.additionalredeemable = null;
                user.userassets = 0;
                user.isadmin=false; 
                user.validatedUser=false;
                
                
                _context.Add(user);
                await _context.SaveChangesAsync();

                // configuration of email 
                var emailSender = "*****@*****.**";
                var password = "******";
                var activateUrl = HttpContext.Session.GetString("urlHome")+"user/ActivateEmail/"+user.id;

                SmtpClient client = new SmtpClient("smtp.gmail.com", 587); 
                client.EnableSsl = true; 
                client.Timeout = 100000; 
                client.DeliveryMethod = SmtpDeliveryMethod.Network; 
                client.UseDefaultCredentials = false;  
                client.Credentials = new NetworkCredential(emailSender, password);
                 
                var subject = "Cfunding Account Validation"; 
                var body = "Thank you for registering!<br>Please activate your account by clicking the link below:<br><a>"+activateUrl+"</a><br>Regards,<br>Cfunding Team.";
                MailMessage mailMessage = new MailMessage (emailSender, user.useremail, subject, body); 
                mailMessage.IsBodyHtml = true;
                mailMessage.BodyEncoding = UTF8Encoding.UTF8; 

                client.Send(mailMessage); 
                
                 return Json(user);
            }
            return Json(user);
        }
        public async Task <IActionResult> Create([Bind("id,projectname,projectdescription,projectamounttoraise,projectcreationdate,projectclosingdate,projectimage1,projectimage2,projectimage3,projectimage4,fkuserid,fkcategoryid,nbshareordinary,nbsharepreferencial,nbsharenonvoting,nbshareredeemable")] project project, IFormFile fileOne, IFormFile fileTwo, IFormFile fileThree, IFormFile fileFour, int fkuser, int fkcategory, int nbshareordinary, int nbsharepreferencial, int nbsharenonvoting, int nbshareredeemable)
        {
            if (ModelState.IsValid)
            {
                // photo upload 1
                if (fileOne == null || fileOne.Length == 0)
                {
                    project.projectimage1 = "images/noImageAvailable.jpg";
                }
                else
                {
                    // if a photo was uploaded save it into the server
                    var path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileOne.FileName);
                    using (var stream1 = new FileStream(path1, FileMode.Create))
                    {
                        await fileOne.CopyToAsync(stream1);
                    }
                    project.projectimage1 = "images/" + fileOne.FileName;
                }

                // photo upload 2
                if (fileTwo == null || fileTwo.Length == 0)
                {
                    project.projectimage2 = "images/noImageAvailable.jpg";
                }
                else
                {
                    var path2 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileTwo.FileName);
                    using (var stream2 = new FileStream(path2, FileMode.Create))
                    {
                        await fileTwo.CopyToAsync(stream2);
                    }
                    project.projectimage2 = "images/" + fileTwo.FileName;
                }

                // photo upload 3
                if (fileThree == null || fileThree.Length == 0)
                {
                    project.projectimage3 = "images/noImageAvailable.jpg";
                }
                else
                {
                    var path3 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileThree.FileName);
                    using (var stream3 = new FileStream(path3, FileMode.Create))
                    {
                        await fileThree.CopyToAsync(stream3);
                    }
                    project.projectimage3 = "images/" + fileThree.FileName;
                }

                // photo upload 4
                if (fileFour == null || fileFour.Length == 0)
                {
                    project.projectimage4 = "images/noImageAvailable.jpg";
                }
                else
                {
                    var path4 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileFour.FileName);
                    using (var stream4 = new FileStream(path4, FileMode.Create))
                    {
                        await fileFour.CopyToAsync(stream4);
                    }
                    project.projectimage4 = "images/" + fileFour.FileName;
                }
                // select the user who owns the project
                project.fkuser = (user)_context.users.First(user => user.id == fkuser);
                // select the project category
                project.fkcategory = (category)_context.categories.First(category => category.id == fkcategory);

                // add the project record and save changes
                _context.Add(project);
                await _context.SaveChangesAsync();

                //update the owner number of shares and save changes
                user currentUser = _context.users.First(user => user.id == fkuser);
                currentUser.nbshareordinary     = currentUser.nbshareordinary - nbshareordinary;
                currentUser.nbsharepreferencial = currentUser.nbsharepreferencial - nbsharepreferencial;
                currentUser.nbsharenonvoting    = currentUser.nbsharenonvoting - nbsharenonvoting;
                currentUser.nbshareredeemable   = currentUser.nbshareredeemable - nbshareredeemable;

                _context.users.Update(currentUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = project.id }));
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList();
            }
            //return View(project);
            return(RedirectToAction("Index", "Home"));
        }