Пример #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());
        }
        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));
        }
        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());
        }
        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
        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));
        }
        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));
        }
        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
        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
        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
        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();
 }