コード例 #1
0
        public async Task <IActionResult> CreateEvent(Event @event)
        {
            _context.Add(@event);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #2
0
        public async Task <IReadOnlyList <ProductType> > CreateProductTypeAsync(ProductType productType)
        {
            var types = _context.ProductTypes;

            _context.Add(productType);
            _context.SaveChanges();
            return(await _context.ProductTypes.ToListAsync());
        }
コード例 #3
0
        public async Task <IActionResult> Create(Event @event)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Description", @event.CategoryId);
            ViewData["CityId"]     = new SelectList(_context.Cities, "Id", "Name", @event.CityId);
            return(View(@event));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,EventDate,Description,Picture,People,Duration,CityId,ClientId,CategoryId")] Event @event)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", @event.CategoryId);
            ViewData["CityId"]     = new SelectList(_context.Clities, "Id", "Name", @event.CityId);
            ViewData["ClientId"]   = new SelectList(_context.Clients, "Id", "Id", @event.ClientId);
            return(View(@event));
        }
コード例 #5
0
        public async Task <IActionResult> CreateEvent(Event @event)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.ClientId       = _context.Clients.Include(u => u.User).ToList();
            ViewData["CityId"]     = new SelectList(_context.Cities, "Id", "Name", @event.CityId);
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", @event.CategoryId);
            return(View());
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,MiddleName,Surame")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
コード例 #7
0
ファイル: LadataController.cs プロジェクト: cmatskas/dfedemo
        public async Task <IActionResult> Create([Bind("Name")] Ladata ladata)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ladata);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ladata));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("Id,MaterialName")] Material material)
        {
            if (ModelState.IsValid)
            {
                _context.Add(material);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(material));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("Id,Nom,Prenom,Telephone")] ContactModel contactModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contactModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contactModel));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("Id,InstrumentTypeName")] InstrumentType instrumentType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(instrumentType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(instrumentType));
        }
コード例 #11
0
        public async Task <IActionResult> Create([Bind("Id,Name,Cost,Count,IdBrandInstrument,IdMaterialInstrument,IdCountryInstrument,IdInstrumentTypeInstrument,IdShopInstrument")] Instrument instrument)
        {
            if (ModelState.IsValid)
            {
                _context.Add(instrument);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(instrument));
        }
コード例 #12
0
        public async Task <IActionResult> Create([Bind("id,Name,Descripcion,Slung")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
コード例 #13
0
        public async Task <IActionResult> Create([Bind("Id,Count,InstrumentCheque,CustomerCheque")] Cheque cheque)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cheque);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cheque));
        }
コード例 #14
0
        public async Task <IActionResult> Create([Bind("Id,BrandName")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brand));
        }
コード例 #15
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,FixedPhone,Email,CellPhone,Address")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
コード例 #16
0
        public async Task <IActionResult> Create([Bind("Id,Name,MiddleName,Surame,IdShopStaff,IdJobStaff")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                _context.Add(staff);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staff));
        }
コード例 #17
0
        public async Task <IActionResult> Create(Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
コード例 #18
0
        public async Task <IActionResult> Create([Bind("Id,Address,City,PhoneNumber")] Shop shop)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shop);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shop));
        }
コード例 #19
0
        public async Task <IActionResult> Create([Bind("Id,Firstname,Surname,Email")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
コード例 #20
0
        public async Task <IActionResult> Create([Bind("Id,CountryName")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
コード例 #21
0
ファイル: LoanController.cs プロジェクト: ssubrata/NgoPro
        public async Task <IActionResult> Create([Bind("Id,LoanAmount,LoanDate,AccountId")] Loan loan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loan);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Detail", new { id = loan.AccountId }));
            }
            ViewData["AccountId"] = new SelectList(_context.Accounts, "Id", "Id", loan.AccountId);
            return(View(loan));
        }
コード例 #22
0
ファイル: BookController.cs プロジェクト: ssubrata/NgoPro
        public async Task <IActionResult> Create([Bind("Id,BookName,IsActive,PaymentAmount,PaymentMethodId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PaymentMethodId"] = new SelectList(_context.PaymentMethods, "Id", "Id", book.PaymentMethodId);
            return(View(book));
        }
コード例 #23
0
ファイル: DepositsController.cs プロジェクト: ssubrata/NgoPro
        public async Task <IActionResult> Create([Bind("Id,DepositAmount,DepositDate,AccountId")] Deposit deposit)
        {
            if (ModelState.IsValid)
            {
                _context.Add(deposit);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = deposit.AccountId }));
            }
            ViewData["AccountId"] = new SelectList(_context.Accounts, "Id", "Id", deposit.AccountId);
            return(View(deposit));
        }
コード例 #24
0
        public async Task <IActionResult> Create([Bind("ParkId,Name,Description,City,State,WebsiteLink,ParkMapLink")] Park park, List <IFormFile> files)
        {
            if (ModelState.IsValid)
            {
                // 1. Save the park model first, creates a unique id for the inserted park.
                _context.Add(park);
                await _context.SaveChangesAsync();

                // 2. Save the ImageFiles in Images folder and FileName in db.
                await SaveParkImageFiles(park, files);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(park));
        }
コード例 #25
0
        public IActionResult PutPart(int id, [FromBody] Part part)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            if (id != part.ID)
            {
                return(HttpBadRequest());
            }

            DateTime?lastMod         = _context.Parts.AsNoTracking().Where(x => x.ID == part.ID).FirstOrDefault().LastTimeModified;
            DateTime comparationDate = DateTime.Now.AddHours(-4);

            if (lastMod < comparationDate) //jeœli poprzednia modyfikacja by³a ju¿ dawno, zrób kopiê
            {
                PartBackup newPB = new PartBackup();
                newPB.Define(_context.Entry(part).Entity);
                _context.Add(newPB);
            }

            part.LastTimeModified = DateTime.Now;

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

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PartExists(id))
                {
                    return(HttpNotFound());
                }
                else
                {
                    throw;
                }
            }

            return(new HttpStatusCodeResult(StatusCodes.Status204NoContent));
        }
コード例 #26
0
        public IActionResult Post(Person person)
        {
            ICollection <ValidationResult> results;

            if (!Helpers.Validate(person, out results))
            {
                return(BadRequest(results.ToString()));
            }

            using (DataDbContext db = new DataDbContext())
            {
                try
                {
                    db.Add(person);
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }
            return(StatusCode(201));
        }
コード例 #27
0
        public IActionResult Compose(string Receiver, string Title, string Content, bool send)
        {
            if (Receiver.IndexOf(',') != -1)
            {
                string[] receivers = Receiver.Split(',');
                var      mail      = new Conversations();
                mail.title   = Title;
                mail.content = Content;
                dbContext.Add(mail);
                dbContext.SaveChanges();
                foreach (var item in receivers)
                {
                    if (item == "")
                    {
                        break;
                    }
                    Users user = dbContext.Users.FirstOrDefault(x => x.Username == item);
                    var   md   = new EmailDetail();
                    md.senderId       = HttpContext.Session.GetInt32("userId");
                    md.receiverId     = user.ID;
                    md.conversationId = mail.id;
                    dbContext.Add(md);
                    dbContext.SaveChanges();
                }
            }

            // if (Receiver.IndexOf(',') != -1)
            // {
            //     string[] userNames = Receiver.Split(",");
            //     var converstion = new Conversations();
            //     converstion.title = Title;
            //     converstion.content = Content;
            //     converstion.mailDate = DateTime.Now;
            //     dbContext.Conversations.Add(converstion);
            //     dbContext.SaveChanges();
            //     foreach (var item in userNames)
            //     {
            //         Console.WriteLine("item: " + item);
            //     }
            //     foreach (var item in userNames)
            //     {
            //         if (item == "")
            //         {
            //             break;
            //         }

            //         var emailDetail = new EmailDetail();
            //         int? userId = HttpContext.Session.GetInt32("userId");
            //         var sender = new Users();
            //         sender = dbContext.Users.FirstOrDefault(s => s.ID == userId);
            //         var user = new Users();
            //         user = dbContext.Users.FirstOrDefault(acc => acc.Username == item);
            //         if (user == null)
            //         {
            //             send = false;
            //             HttpContext.Session.SetString("Compose", "false");
            //             ViewBag.Send = send;
            //             return Redirect("/?Compose=" + send);
            //         }
            //         else
            //         {
            //             emailDetail.senderId = sender.ID;
            //             emailDetail.receiverId = user.ID;
            //             emailDetail.conversations = converstion;
            //             try
            //             {
            //                 converstion.state = Conversations.messageStatus.success;
            //                 send = true;
            //             }
            //             catch (System.Exception)
            //             {
            //                 converstion.state = Conversations.messageStatus.faild;
            //             }
            //             dbContext.EmailDetails.Add(emailDetail);
            //             dbContext.SaveChanges();
            //             return Redirect("/");


            //         }

            //     }
            // }
            else
            {
                var converstion = new Conversations();
                var emailDetail = new EmailDetail();
                int?userId      = HttpContext.Session.GetInt32("userId");
                var sender      = new Users();
                sender = dbContext.Users.FirstOrDefault(s => s.ID == userId);
                var user = new Users(Receiver);
                user = dbContext.Users.FirstOrDefault(acc => acc.Username == Receiver);
                if (user == null)
                {
                    send = false;
                    HttpContext.Session.SetString("Compose", "false");
                    ViewBag.Send = send;
                    return(Redirect("/?Compose=" + send));
                }
                else
                {
                    emailDetail.senderId      = sender.ID;
                    emailDetail.receiverId    = user.ID;
                    converstion.title         = Title;
                    converstion.content       = Content;
                    converstion.mailDate      = DateTime.Now;
                    emailDetail.conversations = converstion;
                    try
                    {
                        converstion.state = Conversations.messageStatus.success;
                        send = true;
                    }
                    catch (System.Exception)
                    {
                        converstion.state = Conversations.messageStatus.faild;
                    }
                    dbContext.EmailDetails.Add(emailDetail);
                    dbContext.SaveChanges();
                }
            }

            return(Redirect("/"));
        }
コード例 #28
0
 public void Add <T>(T entity) where T : class
 {
     _context.Add(entity);
 }
コード例 #29
0
 public async Task Create(T entity)
 {
     //await Task.Run(()=>InitiateConnection());
     _datadbContext.Add(entity);
     _datadbContext.SaveChanges();
 }