예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,EnlistDate,TournementId,AspNetUsersId")] ContestentsCreateEditModelView contestentsCreateEditModelView)
        {
            if (ModelState.IsValid)
            {
                _appContext.Add(contestentsCreateEditModelView);
                await _appContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contestentsCreateEditModelView));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,RegistrationStartDate,RegistrationEndDate,TournementStartDate,TournementEndDate")] Tournement tournement)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tournement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tournement));
        }
예제 #3
0
        private async Task LoadXmlDocumentAsync(Guid projectId, UploadFileViewModel model, string docName)
        {
            using (var memoryStream = new MemoryStream())
            {
                await model.File.CopyToAsync(memoryStream);

                memoryStream.Position = 0;
                XmlDocument docs = new XmlDocument();
                docs.Load(memoryStream);
                XmlNodeList dataNodes = docs.GetElementsByTagName("data");

                var lang = await _context.Languages.Where(w => w.Id == model.LanguageId).SingleOrDefaultAsync();

                var project = await _context.Projects.Where(x => x.Id == projectId).SingleOrDefaultAsync();

                var doc = await _context.DocumentTypes.Where(w => w.Id == model.DocumentTypeId).SingleOrDefaultAsync();

                var projectDocument = new ProjectDocument
                {
                    Name         = docName,
                    Language     = lang,
                    Project      = project,
                    DocumentType = doc,
                    AddedDate    = DateTime.Now
                };

                _context.Add(projectDocument);

                if (_context.SaveChanges() > 0)
                {
                    foreach (XmlNode item in dataNodes)
                    {
                        var nodeId     = item.Attributes["name"].Value;
                        var nodeValue  = item.SelectSingleNode("value").InnerText;
                        var dictionary = new ProjectDocumentDictionary
                        {
                            Document = projectDocument,
                            Name     = nodeId,
                            Value    = nodeValue
                        };
                        _context.Add(dictionary);
                    }

                    var pro = _context.Projects.Where(w => w.Id == projectId).FirstOrDefault();
                    pro.HasDocument = true;

                    _context.Update(pro);

                    await _context.SaveChangesAsync();
                }
            }
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,RegistrationStartDate,RegistrationEndDate,TournementStartDate,TournementEndDate")] TournementViewModel model)
        {
            var tournement = new Tournement();

            if (ModelState.IsValid)
            {
                tournement.Id   = model.Id;
                tournement.Name = model.Name;
                tournement.RegistrationEndDate   = model.RegistrationEndDate;
                tournement.RegistrationStartDate = model.RegistrationStartDate;
                tournement.TournementEndDate     = model.TournementEndDate;
                tournement.TournementStartDate   = model.TournementStartDate;
                _context.Add(tournement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tournement));
        }
예제 #5
0
        public async Task <IActionResult> Post(NewCommentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var result = new Comment
                {
                    CommentText = model.WrittenText,
                    CommentDate = DateTime.Now,
                    PostId      = model.PostId,
                    FullName    = $"{user.Name} {user.Surname}"
                };

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

                return(RedirectToAction("Post"));
            }
            return(View());
        }
예제 #6
0
        public async Task <IActionResult> NewPost(NewPostViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var post = new Post
                {
                    Title       = model.Title,
                    Message     = model.Message,
                    CreatedTime = DateTime.Now,
                    Employee    = user,
                    IsImportant = model.IsImportant
                };
                _context.Add(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Posts"));
            }

            return(View(model));
        }