예제 #1
0
        //Project Creator creates a FundingPackage
        public FundingPackage CreateFundingPackage(
            CreateFundingPackageOptions fundOptions)
        {
            //Elegxos gia null options
            if (fundOptions == null)
            {
                return(null);
            }
            var projectId = project_.GetProjectById(fundOptions.ProjectId);

            if (projectId == null ||
                string.IsNullOrEmpty(fundOptions.DescriptionGift) ||
                fundOptions.Deposit <= 0)
            {
                return(null);
            }

            var fundingPackage = new FundingPackage()
            {
                FixedPackageAmount = fundOptions.FixedPackageAmount,
                Deposit            = fundOptions.Deposit,
                DescriptionGift    = fundOptions.DescriptionGift
            };

            context_.Add(fundingPackage);
            context_.SaveChanges();
            return(fundingPackage);
        }
예제 #2
0
        public FundingPackage CreateFundingPackage(CreateFundingPackageOptions options)
        {
            if (options == null)
            {
                return null;
            }

            var project = projectService_.Search(new SearchProjectOptions
            {
                ProjectId = options.ProjectId
            }).SingleOrDefault();

            if (project == null)
            {
                return null;
            }

            var fp = new FundingPackage()
            {
                Name = options.Name,
                Description = options.Description,
                Price = options.Price,

            };

            project.FundingPackages.Add(fp);
            context_.Update(project);
            context_.Add(fp);

            if (context_.SaveChanges() > 0)
            {
                return fp;
            }
            return null;
        }
        public IActionResult Create(FundingPackage fundingPackage)
        {
            if (ModelState.IsValid)
            {
                _fundingPackage.Add(fundingPackage);

                return(RedirectToAction("ShowMine", "Project"));
            }

            return(RedirectToAction("Index", "Home"));
        }
예제 #4
0
        public FundingPackage AddFundingPackage(FundingPackageOption fundingPackageOption)   //ok
        {
            Project project = db.Projects.Find(fundingPackageOption.ProjectId);
            FundingPackageManagment fundingPackageManager = new FundingPackageManagment(db);
            FundingPackage          fundingPackage        = fundingPackageManager.CreateFundingPackage(fundingPackageOption);

            project.FundingPackages.Add(fundingPackage);

            db.SaveChanges();
            return(fundingPackage);
        }
        public IActionResult Create(int id)
        {
            var project = _projectService.GetById(id);

            if (project.UserCreator.Id == User.GetUsername())
            {
                var fundingpackage = new FundingPackage()
                {
                    Project   = project,
                    ProjectId = project.ProjectId
                };

                return(View(fundingpackage));
            }

            return(RedirectToAction("Index", "Home"));
        }
        // OK
        public StatusCodes CreateFundingPackage(FundingPackageModel source, ClaimsIdentity identity, int projectId, bool isForDonations)
        {
            try
            {
                //get the project
                var _project = uow.ProjectRepository.FindById(projectId);

                if (_project == null)
                {
                    return(StatusCodes.NOT_FOUND);
                }

                else
                {
                    //check if current user is the projectId's creator
                    //else return NOT ALLOWED
                    long requestorUserId = GetRequestorIdFromIdentity(identity);

                    if (_project.User.Id != requestorUserId)
                    {
                        return(StatusCodes.NOT_AUTHORIZED);
                    }

                    var _projectFundingPackage = new FundingPackage()
                    {
                        ProjectId             = projectId,
                        AttachmentSetId       = source.AttachmentSetId,
                        Title                 = source.Title,
                        PledgeAmount          = (isForDonations ? null : source.PledgeAmount),
                        Description           = source.Description,
                        WhenDateTime          = DateTime.Now,
                        EstimatedDeliveryDate = DateTime.Now
                                                //EstimatedDeliveryDate = (isForDonations? DateTime.Now : source.EstimatedDeliveryDate)
                    };

                    uow.FundingPackageRepository.Insert(_projectFundingPackage, true);
                }

                return(StatusCodes.OK);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public FundingPackage CreateFundingPackage(FundingPackageOption fundingPackageOption)   //ok
        {
            IProjectManager projMng = new ProjectManagment(db);
            Project         project = new Project();

            project = db.Projects.Find(fundingPackageOption.ProjectId);
            FundingPackage fundingPackage = new FundingPackage
            {
                Price   = fundingPackageOption.Price ?? 0,
                Reward  = fundingPackageOption.Reward,
                Project = project
            };

            db.FundingPackages.Add(fundingPackage);
            db.SaveChanges();

            return(fundingPackage);
        }
        public BackerFundingPackage Fund(FundingPackage fundingPackage, int backerId, int projectId) //ok
        {
            Project project = db.Projects.Find(projectId);

            //Backer backer = db.Backers.Find(backerId);

            project.TotalFundings += fundingPackage.Price;

            BackerFundingPackage backerFundingPackage = new BackerFundingPackage
            {
                Backer         = db.Backers.Find(backerId),
                FundingPackage = fundingPackage,
                Project        = project
            };

            db.BackerFundingPackages.Add(backerFundingPackage);

            db.SaveChanges();
            return(backerFundingPackage);
        }
        //Project Creator creates a FundingPackage
        public FundingPackage CreateFundingPackage(
            CreateFundingPackageOptions fundOptions)
        {
            //Elegxos gia null options
            if (fundOptions == null)
            {
                return(null);
            }

            if (fundOptions.FixedPackageAmount == 0m ||
                string.IsNullOrEmpty(fundOptions.DescriptionGift))
            {
                return(null);
            }

            var fundingPackage = new FundingPackage()
            {
                DescriptionGift = fundOptions.DescriptionGift
            };

            context_.Add(fundingPackage);
            context_.SaveChanges();
            return(fundingPackage);
        }
예제 #10
0
 public void Add(FundingPackage fundingPackage)
 {
     context_.Add(fundingPackage);
     context_.SaveChanges();
 }
예제 #11
0
        public Project CreateProject(CreateProjectOptions projectOptions)
        {
            if (projectOptions == null)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(projectOptions.Title) ||
                projectOptions.Budget <= 0 ||
                string.IsNullOrWhiteSpace(projectOptions.Description) ||
                projectOptions.UserId == 0)
            {
                return(null);
            }

            var project = new Project()
            {
                Title        = projectOptions.Title,
                Budget       = projectOptions.Budget,
                Description  = projectOptions.Description,
                Category     = ProjectCategoryUti.GetCategory(projectOptions.Category),
                CreationDate = DateTime.Now,
                User         = context_.Set <User>().Find(projectOptions.UserId)
            };

            context_.Add(project);
            context_.SaveChanges();

            if (projectOptions.FundingPackages.Count == 0)
            {
                projectOptions.FundingPackages = new List <string>()
                {
                    "funding package 1"
                };
            }

            //if title is not unique
            try
            {
                foreach (string package in projectOptions.FundingPackages)
                {
                    var fundingPackage = new FundingPackage
                    {
                        Deposit         = 1000,
                        DescriptionGift = package,
                        Project         = project
                    };

                    context_.Set <FundingPackage>().Add(fundingPackage);
                }
                //context_.Set<Project>().Add(project);
                context_.SaveChanges();
            }
            catch (Exception)
            {
                return(null);
            }

            context_.SaveChanges();
            return(new Project
            {
                Id = project.Id,
                Budget = project.Budget,
                Category = project.Category,
                CreationDate = project.CreationDate,
                Description = project.Description,
                StatusProject = project.StatusProject,
                Title = project.Title
            });
        }
        static void Main(string[] args)
        {
            using CrmDbContext db = new CrmDbContext();

            IProjectManager        projectMng  = new ProjectManagment(db);
            IProjectCreatorManager projCrMng   = new ProjectCreatorManagment(db);
            IBackerManager         backerMangr = new BackerManagment(db);
            IFundingPackageManager fundMangr   = new FundingPackageManagment(db);


            ProjectCreatorOption projectCreatorOption = new ProjectCreatorOption
            {
                FullName = "Stelios",
                Address  = "SKG",
                Email    = "email"
            };
            ProjectCreator projectCreator = projCrMng.CreateProjectCreator(projectCreatorOption);

            BackerOption backerOpt = new BackerOption()
            {
                FullName = "mixalis",
                Address  = "ptolem",
                Email    = "*****@*****.**",
                Phone    = "12345"
            };

            ProjectOption projectOption = new ProjectOption
            {
                ProjectCreatorId = 1,
                Title            = "B",
                Description      = "description B",
                StatusUpdate     = "status B",
                TotalFundings    = 0m,
                Goal             = 1000m,
                Category         = "Fashion",
                Active           = true
            };



            FundingPackageOption fundOpt = new FundingPackageOption
            {
                Price     = 158,
                Reward    = "nadd",
                ProjectId = 2
            };

            //Backer backer = backerMangr.CreateBacker(backerOpt);
            //Project project = projectMng.CreateProject(projectOption);
            FundingPackage funding = projCrMng.AddFundingPackage(fundOpt);

            //Console.WriteLine(
            //          $"Id= {backer.Id} Address= {backer.Address} Email= {backer.Email}  ");

            //Console.WriteLine(
            //          $"Id= {project.Id} Description= {project.Description} StatusUpdate= {project.StatusUpdate}  ");

            //Console.WriteLine(
            //          $"Id= {funding.Id} Reward= {funding.Reward} ");

            // BackerFundingPackage bfp = backerMangr.Fund(funding, 1);
            //BackerFundingPackage bfp2 = backerMangr.Fund(2, 2, 1);
            //BackerFundingPackage bfp3 = backerMangr.Fund(3, 2, 1);

            //Console.WriteLine(
            //          $"Id= {bfp.Id} Backer= {bfp.Backer.Id} FundingPackage= {bfp.FundingPackage.Id}  ");

            List <BackerFundingPackage> bfps = backerMangr.ShowFundingPackageByBacker(1);

            foreach (var bfp in bfps)
            {
                Console.WriteLine(
                    $"Title= {bfp.Backer} TotalFundings= {bfp.Project} Goal= {bfp.Id}  ");
            }
        }