예제 #1
0
        private static void JoinBattleAndSamurai()
        {
            //Samurai and Battle already exist and we have their IDs
            var sbJoin = new SamuraiBattle {
                SamuraiId = 2, BattleId = 1
            };

            _context.Add(sbJoin);
            _context.SaveChanges();
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("AboutZooID,Description,Date")] AboutZoo aboutZoo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aboutZoo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aboutZoo));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("AnimalId,AnimalName,AnimalDescription")] Animals animals)
        {
            if (ModelState.IsValid)
            {
                _context.Add(animals);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(animals));
        }
예제 #4
0
        // Збереження нового кота
        private void SaveCat_Click(object sender, RoutedEventArgs e)
        {
            newCat.EnableValidation = true;
            if (string.IsNullOrEmpty(newCat.Error))
            {
                MessageBox.Show("Додавання успішне");
                var extension = Path.GetExtension(FileName);
                var imageName = Path.GetRandomFileName() + extension;
                var dir       = Directory.GetCurrentDirectory();
                var saveDir   = Path.Combine(dir, "images");
                if (!Directory.Exists(saveDir))
                {
                    Directory.CreateDirectory(saveDir);
                }
                var fileSave = Path.Combine(saveDir, imageName);
                File.Copy(FileName, fileSave);

                var cat =
                    new AppCat
                {
                    Name     = tbName.Text,
                    Gender   = _gender,
                    Birthday = (DateTime)dpDate.SelectedDate,
                    Details  = tbDetails.Text,
                    Image    = fileSave
                };
                cat.AppCatPrices = new List <AppCatPrice>
                {
                    new AppCatPrice
                    {
                        CatId      = cat.Id,
                        DateCreate = DateTime.Now,
                        Price      = decimal.Parse(tbPrice.Text)
                    }
                };
                _context.Add(cat);
                _context.SaveChanges();

                _cats.Add(new CatVM
                {
                    Id       = cat.Id,
                    Name     = cat.Name,
                    Birthday = cat.Birthday,
                    Details  = cat.Details,
                    ImageUrl = cat.Image
                });

                this.Close();
            }
            else
            {
                MessageBox.Show(newCat.Error);
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Title,CreateTime,LastUpdateTime")] CompetitionField competitionField)
        {
            if (ModelState.IsValid)
            {
                competitionField.CreateTime = DateTime.Now;
                _context.Add(competitionField);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(competitionField));
        }
        public async Task <IActionResult> Create([Bind("AnnouncementId,AnnouncementTitle,AnnouncementText,Date")] Announcements announcements)
        {
            if (ModelState.IsValid)
            {
                announcements.Date = DateTime.Now;
                _context.Add(announcements);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(announcements));
        }
        public async Task <IActionResult> Create([Bind("Id,FullName,PhoneNumber,PhoneNumberConfirmed,Email,EmailConfirmed,PhoneNumberVerifyCode,EmailVerifyCode,Password,Avatar,Role,AccessFailedCount,CreateTime,LastUpdateTime,IsDeleted,IsActive")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Id = Guid.NewGuid();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("Name,Quantity,Price,ProductTypeId,Id,CreatedOnUtc")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductTypeId"] = new SelectList(_context.Set <ProductType>(), "Id", "Name", product.ProductTypeId);
            return(View(product));
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("StatusId,Title,CreateTime,LastUpdateTime,Editable")] Status status)
        {
            if (ModelState.IsValid)
            {
                status.CreateTime = DateTime.Now;
                _context.Add(status);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(status));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,CreateTime,LastUpdateTime,CompetitionBranchId,UserId")] CompetitionSubject competitionSubject)
        {
            if (ModelState.IsValid)
            {
                competitionSubject.CreateTime = DateTime.Now;
                _context.Add(competitionSubject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompetitionBranchId"] = new SelectList(_context.CompetitionBranchs, "Id", "Title", competitionSubject.CompetitionBranchId);
            return(View(competitionSubject));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("Id,Subject,StatusId")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                ticket.Id = (Guid.NewGuid()).ToString();
                _context.Add(ticket);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StatusId"] = new SelectList(_context.Statues, "StatusId", "Title", ticket.StatusId);
            return(View(ticket));
        }
예제 #12
0
        public async Task <IActionResult> Create(IFormCollection formCollection, CreateParticipantViewModel participant)
        {
            Participant participantToAdd = new Participant();

            if (ModelState.IsValid)
            {
                participantToAdd.Id                   = (Guid.NewGuid()).ToString();
                participantToAdd.CreateTime           = DateTime.Now;
                participantToAdd.Subject              = participant.Subject;
                participantToAdd.StatusId             = 1;
                participantToAdd.Description          = participant.Description;
                participantToAdd.UserId               = HttpContext.User.Identity.Name;
                participantToAdd.CompetitionSubjectId = participant.CompetitionSubjectId;

                if (formCollection.Files != null)
                {
                    foreach (var file in formCollection.Files)
                    {
                        var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

                        //var id = HttpContext.User.Identity.Name;
                        // Some browsers send file names with full path.
                        // We are only interested in the file name.
                        var format       = Path.GetExtension(fileContent.FileName.ToString().Trim('"'));
                        var filename     = Guid.NewGuid().ToString() + format;
                        var physicalPath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads\" + HttpContext.User.Identity.Name, filename);
                        var path         = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads\" + HttpContext.User.Identity.Name);

                        bool exists = Directory.Exists(path);

                        if (!exists)
                        {
                            Directory.CreateDirectory(path);
                        }

                        using (var fileStream = new FileStream(physicalPath, FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }

                        participantToAdd.AttachedFile = filename;
                    }
                }

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(participantToAdd));
        }
 public Employee Criar(Employee entity)
 {
     try
     {
         _db.Add(entity);
         _db.SaveChanges();
         return(entity);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     return(null);
 }
 public void Add(BookCategory bookCategory)
 {
     _context.Add(bookCategory);
 }
예제 #15
0
        private void Save_User_Click(object sender, RoutedEventArgs e)
        {
            us.EnabledValidation = true;

            var extension = Path.GetExtension(FileName);
            var imageName = Path.GetRandomFileName() + extension;
            var dir       = Directory.GetCurrentDirectory();
            var saveDir   = Path.Combine(dir, "images");

            if (!Directory.Exists(saveDir))
            {
                Directory.CreateDirectory(saveDir);
            }
            var fileSave = Path.Combine(saveDir, imageName);

            File.Copy(FileName, fileSave);

            var user =
                new AppUser
            {
                Name        = tbName.Text,
                DebitKredit = _debit_kredit,
                Tranіaction = (DateTime)dpDate.SelectedDate,
                Details     = tbDetails.Text,
                Image       = fileSave
            };

            user.AppTranzactionPrices = new List <AppTranzactionPrice>
            {
                new AppTranzactionPrice
                {
                    UserId     = user.Id,
                    DateCreate = DateTime.Now,
                    Price      = decimal.Parse(this.tbPrice.Text)
                }
            };
            _context.Add(user);



            if (string.IsNullOrEmpty(us.Error))
            {
                MessageBox.Show("Ура, пошло");
                _context.SaveChanges();
            }

            else
            {
                MessageBox.Show(us.Error);
            }


            _users.Add(new UserVM
            {
                Id          = user.Id,
                Name        = user.Name,
                Tranіaction = user.Tranіaction,
                Details     = user.Details,
                Image       = user.Image
            });
            this.Close();
        }