コード例 #1
0
ファイル: PetShopService.cs プロジェクト: ArmNem/PetShop
        public List <Pet> GetAllByType(Pettype type)
        {
            var list  = _petShopRepo.GetPets();
            var query = list.Where(pet => pet.Type.Equals(type));

            return(query.ToList());
        }
コード例 #2
0
        public Pettype NewType(string name)
        {
            var newtype = new Pettype()
            {
                TypeName = name
            };

            return(newtype);
        }
コード例 #3
0
 public ActionResult <Pettype> Put(int id, [FromBody] Pettype type)
 {
     try
     {
         return(StatusCode(202, _petTypeService.UpdateType(type)));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
コード例 #4
0
 public ActionResult <Pettype> Post([FromBody] Pettype type)
 {
     try
     {
         return(StatusCode(201, _petTypeService.CreateType(type)));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
コード例 #5
0
ファイル: PetTypeRepository.cs プロジェクト: ArmNem/PetShop
        public Pettype UpdateType(Pettype updatetype)
        {
            var typefromDB = this.FindPetTypeById(updatetype.Id);

            if (typefromDB != null)
            {
                typefromDB.TypeName = updatetype.TypeName;
                return(typefromDB);
            }

            return(null);
        }
コード例 #6
0
        public ActionResult Update(Guid id)
        {
            Pettype    pet   = _pettypeService.GetByID(id);
            PettypeDTO model = new PettypeDTO();

            model.ID                 = pet.ID;
            model.PettypeName        = pet.PettypeName;
            model.PettypeDescription = pet.PettypeDescription;
            model.SeoTitle           = pet.SeoTitle;
            model.SeoDescription     = pet.SeoDescription;
            return(View(model));
        }
コード例 #7
0
        public Pettype CreateType(Pettype type)
        {
            if (_petTypeRepo.FindPetTypeById(type.Id) == null)
            {
                throw new InvalidDataException("Type not found");
            }

            if (type.TypeName == null)
            {
                throw new InvalidDataException("Type needs a name");
            }
            return(_petTypeRepo.AddType(type));
        }
コード例 #8
0
        public Pettype UpdateType(Pettype updatetype)
        {
            var type = FindTypeById(updatetype.Id);

            if (type.Id != updatetype.Id || updatetype.Id < 1)
            {
                throw new InvalidDataException("Parameter Id and Type Id must be the same");
            }
            if (updatetype.TypeName == null)
            {
                throw new InvalidDataException("Type must have a name");
            }
            type.TypeName = updatetype.TypeName;
            return(type);
        }
コード例 #9
0
        public ActionResult Update(PettypeDTO data)
        {
            Pettype pet = _pettypeService.GetByID(data.ID);

            pet.ID                 = data.ID;
            pet.PettypeName        = data.PettypeName;
            pet.PettypeDescription = data.PettypeDescription;
            pet.SeoTitle           = data.SeoTitle;
            pet.SeoDescription     = data.SeoDescription;



            _pettypeService.Update(pet);
            TempData["Successful"] = "Transaction is successful.";
            return(Redirect("/Admin/Pettype/List"));
        }
コード例 #10
0
ファイル: PetShopService.cs プロジェクト: ArmNem/PetShop
        public Pet NewPet(string name, Pettype type, DateTime birthDate, DateTime soldDate, string color, List <Owner> Owner,
                          double price)
        {
            var newpet = new Pet()
            {
                Name      = name,
                Type      = type,
                BirthDate = birthDate,
                SoldDate  = soldDate,
                Color     = color,
                Owner     = Owner,
                Price     = price
            };

            return(newpet);
        }
コード例 #11
0
ファイル: PetTypeRepository.cs プロジェクト: ArmNem/PetShop
 public Pettype AddType(Pettype type)
 {
     type.Id = _id++;
     types.Add(type);
     return(type);
 }
コード例 #12
0
 public ActionResult Add(Pettype data)
 {
     _pettypeService.Add(data);
     return(Redirect("/Admin/Pettype/List"));
 }