コード例 #1
0
        public Categoria Post([FromBody] Categoria categoria)
        {
            _context.Categorias.Add(categoria);
            _context.SaveChanges();

            return(categoria);
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,Name")] Breed breed)
        {
            if (ModelState.IsValid)
            {
                db.Breeds.Add(breed);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(breed));
        }
コード例 #3
0
ファイル: CatsController.cs プロジェクト: deanswiatek/MvcCat
        public ActionResult Create([Bind(Include = "Id,Name,BreedId")] Cat cat)
        {
            if (ModelState.IsValid)
            {
                db.Cats.Add(cat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BreedId = new SelectList(db.Breeds, "Id", "Name", cat.BreedId);
            return(View(cat));
        }
コード例 #4
0
        public IActionResult Create([FromBody] Cat cat)
        {
            if (cat == null)
            {
                return(BadRequest());
            }

            _context.Cats.Add(cat);
            _context.SaveChanges();

            return(new NoContentResult());
        }
コード例 #5
0
 public void Create(Customer customer)
 {
     if (_context.Customers.Any(x => x.FirstName == customer.FirstName && x.LastName == customer.LastName && x.Email == customer.Email))
     {
         throw new DataException($"There cant be two customers with the same first name, last name and email.\nThe first name of:- '{customer.FirstName.ToString()}',\nLast name of:- '{customer.LastName.ToString()}',\nEmail of:- '{customer.Email.ToString()}'.\nCant be added");
     }
     else if (_context.Customers.Any(x => x.FirstName == customer.FirstName && x.LastName == customer.LastName))
     {
         throw new DataException($"There cant be two customers with the same first name, last name and email.\nThe first name of:- '{customer.FirstName.ToString()}',\nLast name of:- '{customer.LastName.ToString()}'.");
     }
     _context.Customers.Add(customer);
     _context.SaveChanges();
 }
コード例 #6
0
        public void Create(Room room)
        {
            var roomList = GetAllByNumber().OrderBy(x => x.RoomNo).ToList();

            for (int i = 0; i < roomList.Count(); i++)
            {
                if (roomList[i].RoomNo == room.RoomNo)
                {
                    throw new DataException($"Room {room.RoomNo}, Already Exsists");
                }
            }
            if (room.RoomType == RoomType.FamilyRoom && room.MaxNoOfCatsInRoom > 4 || room.RoomType == RoomType.StandardRoom && room.MaxNoOfCatsInRoom > 2)
            {
                throw new DataException("Family room can hold a maximum of 4 cats at a time and standard rooms can hold maximum of 2 cats.");
            }
            else
            {
                room.CheckedIn    = false;
                room.CheckedOut   = false;
                room.BookingEnd   = DateTime.Now;
                room.BookingStart = DateTime.Now;
                room.Booked       = false;
                room.Available    = true;
                room.ID           = Guid.NewGuid();
                _context.Add(room);
                _context.SaveChanges();
            }
        }
コード例 #7
0
        protected override void Seed(CatContext context)
        {
            var breeds = new List <Breed>
            {
                new Breed {
                    Name = "Black"
                },
                new Breed {
                    Name = "Tabby"
                },
                new Breed {
                    Name = "Calico"
                },
                new Breed {
                    Name = "Serval"
                },
                new Breed {
                    Name = "Tiger"
                },
                new Breed {
                    Name = "Persian"
                },
                new Breed {
                    Name = "Jaguar"
                },
                new Breed {
                    Name = "Mountain Lion"
                }
            };

            context.Breeds.AddRange(breeds);
            context.SaveChanges();
        }
コード例 #8
0
        public static void Initialize(CatContext context)
        {
            context.Database.EnsureCreated();

            if (context.cats.Any())
            {
                return;
            }

            var cats = new Cat[]
            {
                new Cat {
                    Name = "MeowMeow1", Color = "Caucasian", Price = 400, FavoriteDish = "Tuna", Birthdate = DateTime.Today
                },
                new Cat {
                    Name = "MeowMeow2", Color = "AfricanAmerican", Price = 500, FavoriteDish = "Tuna", Birthdate = DateTime.Today
                },
                new Cat {
                    Name = "MeowMeow3", Color = "Asian", Price = 450, FavoriteDish = "Tuna", Birthdate = DateTime.Today
                }
            };

            foreach (Cat p in cats)
            {
                context.Add(p);
            }
            context.SaveChanges();
        }
コード例 #9
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.DataBaseView);

            // Get our button from the layout resource,
            // and attach an event to it
            newUserName = FindViewById <EditText>(Resource.Id.dbUserName);
            meowCount   = FindViewById <EditText>(Resource.Id.meowsCount);

            setEditText();

            countClickButton = FindViewById <Button>(Resource.Id.MyButton);
            addUserButton    = FindViewById <Button>(Resource.Id.AddUserButton);


            TextView textView = (TextView)FindViewById(Resource.Id.CatsView);

            await InitializeDb(textView);


            countClickButton.Click += delegate { countClickButton.Text = string.Format("{0} clicks!", count++); };
            addUserButton.Click    += async delegate
            {
                Cat newCat = new Cat()
                {
                    CatId = _db.Cats.Count() + 1, Name = newUserName.Text, MeowsPerSecond = int.Parse(meowCount.Text)
                };
                this._db.Cats.Add(newCat);
                _db.SaveChanges();
                await PrintUsers(textView, _db);
            };
        }
コード例 #10
0
 public void Save(Produto p)
 {
     _context.Produtos.Add(p);
     _context.SaveChanges();
 }
コード例 #11
0
 public int Save()
 {
     return(_context.SaveChanges());
 }