示例#1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,InfoAboutMe,InfoAboutStudy,AboutWork,Achievement,Image")] Portfolio portfolio)
        {
            if (id != portfolio.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(portfolio);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PortfolioExists(portfolio.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(portfolio));
        }
示例#2
0
        public async Task <IActionResult> PutProject(Guid id, Project project)
        {
            if (id != project.ProjectId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutSkill(Guid id, Skill skill)
        {
            if (id != skill.SkillId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <TEntity> Create(TEntity item)
        {
            await _dbSet.AddAsync(item);

            await _context.SaveChangesAsync();

            return(item);
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Id,ContactName,Email,Message,Location")] ContactUsMessage contactUsMessage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contactUsMessage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contactUsMessage));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("Name")] Technology technology)
        {
            if (ModelState.IsValid)
            {
                _context.Add(technology);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(technology));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Label,Body")] Blog blog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(blog));
        }
        public async Task <IActionResult> Create([Bind("Id,ImagePath,Text")] Project project)
        {
            if (ModelState.IsValid)
            {
                project.Id = Guid.NewGuid();
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
示例#9
0
        public async Task <IActionResult> Create([Bind("Id,Paragraph")] AboutMe aboutMe)
        {
            if (ModelState.IsValid)
            {
                aboutMe.Id = Guid.NewGuid();
                _context.Add(aboutMe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aboutMe));
        }
        public async Task PutStockPriceChange(int stockid, StockPriceDto stockPriceDto)
        {
            //locate stock information
            var currentStock = await _portfolioContext.Stocks
                               .Where(p => p.StockId == stockid)
                               .FirstAsync();

            // format date (strip away seconds, milliseconds, etc)
            var baseDate   = stockPriceDto.DateTime;
            var savingDate = new DateTime(
                baseDate.Year,
                baseDate.Month,
                baseDate.Day,
                baseDate.Hour,
                baseDate.Minute,
                0, DateTimeKind.Local);

            // if current stock price is more recent then ...
            // update the .. update time and latest price information
            if (currentStock.LastUpdated <= savingDate)
            {
                currentStock.LatestPrice = stockPriceDto.Price;
                currentStock.LastUpdated = savingDate;
            }

            await CreateStockPriceRecord(stockid, stockPriceDto, savingDate);

            await CalcStockMinuteReturn(stockid, stockPriceDto, savingDate);

            await CalcStockHourReturn(stockid, stockPriceDto, savingDate);

            await CalcStockDailyReturn(stockid, stockPriceDto, savingDate);

            await _portfolioContext.SaveChangesAsync();

            Dictionary <int, double> PortfoliosByPrice = await CreateOrUpdatePortfolioPriceRecord(stockid, savingDate);

            foreach (var portfolioPrice in PortfoliosByPrice)
            {
                var dailyReturnTask  = CalcPortfolioDailyReturn(portfolioPrice.Key, portfolioPrice.Value, savingDate);
                var hourReturnTask   = CalcPortfolioHourReturn(portfolioPrice.Key, portfolioPrice.Value, savingDate);
                var minuteReturnTask = CalcPortfolioMinuteReturn(portfolioPrice.Key, portfolioPrice.Value, savingDate);

                Task.WaitAll(dailyReturnTask, hourReturnTask, minuteReturnTask);
            }

            await _portfolioContext.SaveChangesAsync();

            await _hubContext.Clients.All.SendAsync("UpdatePortfolio");
        }
示例#11
0
        public async Task <User> UpdatePortfolio(User user)
        {
            db.Users.Update(user);
            await db.SaveChangesAsync();

            return(user);
        }
示例#12
0
        public async Task CreateAsync([FromBody] NewPortfolioModel model)
        {
            using (var context = new PortfolioContext())
            {
                var portfolio = syncService.AddPortfolio(context, model.Name, model.ShortName, model.ViewKey);
                var labels    = new DefaultFieldLabels(portfolio.Configuration);
                portfolio.Configuration.Labels = labels.GetDefaultLabels();
                portfolio.IDPrefix             = portfolio.ViewKey.ToUpper();
                context.Portfolios.Add(portfolio);
                await context.SaveChangesAsync();

                portfolio.Configuration.CompletedPhase = portfolio.Configuration.Phases.Single(p => p.ViewKey == PhaseConstants.CompletedViewKey);
                portfolio.Configuration.ArchivePhase   = portfolio.Configuration.Phases.Single(p => p.ViewKey == PhaseConstants.ArchiveViewKey);
                await context.SaveChangesAsync();
            }
        }
        public async Task PostLabel([FromBody] PortfolioConfigAddLabelRequest labelRequest)
        {
            using (var context = new PortfolioContext())
            {
                var portfolio = await context.Portfolios
                                .Include(p => p.Configuration.Labels)
                                .Include(p => p.Configuration.LabelGroups)
                                .SingleAsync(p => p.ViewKey == labelRequest.ViewKey);

                var label = portfolio.Configuration.Labels.SingleOrDefault(l => l.FieldName == labelRequest.FieldName);
                var group = labelRequest.FieldGroup == null ? null : portfolio.Configuration.LabelGroups.Single(l => l.Name == labelRequest.FieldGroup);
                if (label == null)
                {
                    label = new PortfolioLabelConfig();
                    portfolio.Configuration.Labels.Add(label);
                }

                // Update the label's fields
                label       = PortfolioMapper.ConfigMapper.Map(labelRequest, label);
                label.Group = group;

                // Save
                await context.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> Create(CreateUser authorization)
        {
            UserAuthorization userAuthorization = new UserAuthorization();

            userAuthorization.LoginUser    = authorization.LoginUser;
            userAuthorization.HashPassword = authorization.password1; // GetHash.NewHash(authorization.password1);

            if (ModelState.IsValid)
            {
                _context.Add(new UserProfile {
                    NameUser = "******"
                });
                _context.Add(new Education {
                    EducationalInstitution = " "
                });
                _context.Add(new UserServices {
                    NameServices = " "
                });
                _context.Add(new UserWorkplace {
                    UserPosition = " "
                });
                _context.Add(new UserBiography {
                    UserHistory = " "
                });
                _context.Add(userAuthorization);
                await _context.SaveChangesAsync();

                await EmailService.SendEmailAsync("*****@*****.**", "Новый пользователь", authorization.LoginUser);

                ViewBag.Nice = "Регистрация прошла успешно, войдите в систему используя свой логин и пароль";
                return(View("Index"));
            }
            else
            {
                ViewBag.er = "Что то пошло не так!";
                return(View());
            }
        }
示例#15
0
        public async Task ArchiveTest()
        {
            // Test data setup - use a separate prefix so no risk of interfering with other tests
            await ProjectClient.EnsureTestProjects(testProjectCount, prefix);

            var testProjects = await ProjectClient.GetTestProjectsAsync(prefix);

            var expectedArchivedProjects = new List <string>();

            using (var context = new PortfolioContext())
            {
                // Get the config
                var portfolioConfig = await context.PortfolioConfigurations
                                      .Include(c => c.CompletedPhase)
                                      .Include(c => c.ArchivePhase)
                                      .SingleAsync(p => p.Portfolio.ViewKey == TestSettings.TestPortfolio);

                // Set the timestamp to (half the test project count) days before the age cutoff: this is so half the test projects will get archived.
                var cutoff = DateTime.Today.AddDays(-portfolioConfig.ArchiveAgeDays);
                var latestUpdateTimestamp = cutoff.AddDays(-(testProjectCount / 2));

                // Set the phases and timestamps for the latest updates
                foreach (var project in testProjects.OrderBy(p => p.project_id))
                {
                    var entity = await context.Projects.Include(p => p.LatestUpdate).SingleAsync(p => p.Reservation.ProjectId == project.project_id);

                    entity.LatestUpdate.Phase     = portfolioConfig.ArchivePhase;
                    entity.LatestUpdate.Timestamp = latestUpdateTimestamp;

                    if (latestUpdateTimestamp < cutoff)
                    {
                        expectedArchivedProjects.Add(project.project_id);
                    }

                    latestUpdateTimestamp = latestUpdateTimestamp.AddDays(1);
                }
                await context.SaveChangesAsync();
            }

            // Do the archival and check respoonse
            var response = await PortfolioClient.ArchiveProjectsAsync(TestSettings.TestPortfolio);

            Assert.AreEqual(expectedArchivedProjects.Count, response.ArchivedProjectIds.Length);
            for (int i = 0; i < expectedArchivedProjects.Count; i++)
            {
                Assert.AreEqual(expectedArchivedProjects[i], response.ArchivedProjectIds[i]);
            }
        }
        public async Task DeleteLabel([FromUri] PortfolioConfigDeleteLabelRequest labelRequest)
        {
            using (var context = new PortfolioContext())
            {
                var label = await context.PortfolioConfigurationLabels
                            .SingleOrDefaultAsync(l => l.Configuration.Portfolio.ViewKey == labelRequest.ViewKey && l.FieldName == labelRequest.FieldName);

                if (label != null)
                {
                    context.PortfolioConfigurationLabels.Remove(label);
                    await context.SaveChangesAsync();
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
        }
示例#17
0
        public async Task <bool> DeleteAccount(long accountId)
        {
            var account = await _portfolioContext.Accounts.Where(x => x.AccountId == accountId).FirstOrDefaultAsync().ConfigureAwait(false);

            if (account != null)
            {
                _portfolioContext.Accounts.Remove(account);
                await _portfolioContext.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
示例#18
0
        public Project Create(string title, string body, string externalLink, HttpPostedFileBase imageFile, ICollection <int> categoryIds)
        {
            Project project = new Project()
            {
                Title        = title,
                ExternalLink = externalLink,
                Body         = body
            };

            try
            {
                // create image and set path on project
                string fileName = _imageService.Create(imageFile);

                project.SetImagePath(fileName);

                // add categories to project
                foreach (int categoryId in categoryIds)
                {
                    Category category = _context.Categories.Find(categoryId);
                    if (category != null)
                    {
                        project.Categories.Add(category);
                    }
                }

                _context.Projects.Add(project);
                _context.SaveChangesAsync();

                return(project);
            }
            catch (ImageException e)
            {
                Errors = _imageService.Errors;

                throw new ProjectException(e.Message);
            }
        }
        public async Task <IActionResult> Create(BlogUser blogUser, IFormFileCollection files)
        {
            int    id             = 0;
            string statusPassword = "";

            if (Request.Cookies.ContainsKey("IdUser") && Request.Cookies.ContainsKey("UserPassword"))
            {
                id             = int.Parse(Request.Cookies["IdUser"]);
                statusPassword = Request.Cookies["UserPassword"];
            }

            if (statusPassword == "true" && id > 0)
            {
                if (ModelState.IsValid)
                {
                    blogUser.DateBlog = DateTime.Now;
                    blogUser.IdUser   = id;
                    _context.Add(blogUser);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(View(blogUser));
                }

                ImgBlog img = new ImgBlog();

                int count = 0;
                count = _context.BlogUser.Max(p => p.IdBlog);

                foreach (var file in files)
                {
                    if (file != null)
                    {
                        byte[] imageData = null;

                        using (var fileStream = file.OpenReadStream())
                            using (var ms = new MemoryStream())
                            {
                                fileStream.CopyTo(ms);
                                imageData = ms.ToArray();
                            }

                        string type = file.ContentType;
                        img.IdBlog  = count;
                        img.IdImg   = 0;
                        img.DataImg = imageData;
                        img.IdUser  = id;
                        img.TypeImg = type;

                        _context.Add(img);
                    }
                    await _context.SaveChangesAsync();

                    int lastIdImg = _context.ImgBlog.Max(p => p.IdImg);
                    int lastBlog  = _context.BlogUser.Max(p => p.IdBlog);
                    var blog      = _context.BlogUser.Find(lastBlog);
                    blog.MainImg = lastIdImg;
                    _context.Update(blog);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(Redirect("/UserAuthorization/Index"));
            }
        }
 public async Task Save(CancellationToken cancellationToken)
 {
     await context.SaveChangesAsync(cancellationToken);
 }
        public async Task <IActionResult> Edit(int id, FullUser fullUser, IFormFileCollection files)
        {
            int    idCookie       = 0;
            string statusPassword = "";

            if (Request.Cookies.ContainsKey("IdUser") && Request.Cookies.ContainsKey("UserPassword"))
            {
                idCookie       = int.Parse(Request.Cookies["IdUser"]);
                statusPassword = Request.Cookies["UserPassword"];
            }

            if (statusPassword == "true" && idCookie > 0)
            {
                if (id != fullUser.OneUser.IdUser)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    if (fullUser.BiographyUser != null)
                    {
                        fullUser.BiographyUser.IdUser = id;
                    }
                    _context.Update(fullUser.BiographyUser);
                    if (fullUser.EducationUser != null)
                    {
                        fullUser.EducationUser.IdUser = id;
                    }
                    _context.Update(fullUser.EducationUser);
                    if (fullUser.OneUser != null)
                    {
                        _context.Update(fullUser.OneUser);
                    }
                    if (fullUser.ServicesUser != null)
                    {
                        fullUser.ServicesUser.IdUser = id;
                    }
                    _context.Update(fullUser.ServicesUser);
                    if (fullUser.WorkplaceUser != null)
                    {
                        fullUser.WorkplaceUser.IdUser = id;
                    }
                    _context.Update(fullUser.WorkplaceUser);

                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(View(fullUser));
                }

                ImgUser img = new ImgUser();

                foreach (var file in files)
                {
                    if (file != null)
                    {
                        byte[] imageData = null;

                        using (var fileStream = file.OpenReadStream())
                            using (var ms = new MemoryStream())
                            {
                                fileStream.CopyTo(ms);
                                imageData = ms.ToArray();
                            }


                        string type = file.ContentType;
                        img.IdUser  = id;
                        img.IdImg   = 0;
                        img.DataImg = imageData;
                        img.TypeImg = type;

                        _context.Add(img);
                    }
                    await _context.SaveChangesAsync();

                    int lastIdImg = _context.ImgUser.Where(p => p.IdUser == idCookie).Max(p => p.IdImg);
                    var profile   = _context.UserProfile.Find(idCookie);
                    profile.MainImg = lastIdImg;
                    _context.Update(profile);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToRoute(new
                {
                    controller = "UserProfiles",
                    action = "Details",
                    id = id
                }));
            }
            else
            {
                return(Redirect("/UserAuthorization/Index"));
            }
        }