public ActionResult CreatePet(int memberID, int specieID, string petName)
        {
            if (specieID == 0)
            {
                return(Json(new { Result = "Fail, pet specie is required " }));
            }
            if (String.IsNullOrEmpty(petName))
            {
                return(Json(new { Result = "Fail, name is required" }));
            }
            Pet Checkname = _PetRepo.GetByMemberIDAndNameAndSpecie(memberID, petName, specieID);

            if (Checkname != null)
            {
                return(Json(new { Result = "Fail, The member already have " + (_SpecieRepo.GetById(specieID)).name + " name " + petName }));
            }

            Pet pet = new Pet();

            pet.memberId = memberID;
            pet.specieId = specieID;
            pet.name     = petName;
            _PetRepo.Add(pet);
            return(Json(new { Result = "Success" }));
        }
예제 #2
0
        public ActionResult EditSpecie(int specieId, string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                return(Json(new { Result = "Fail, specie name is required" }));
            }
            Specie type = _SpecieRepo.GetByName(name);

            if (type != null && type.id != specieId)
            {
                return(Json(new { Result = "Fail, specie " + name + " is already exits in the system" }));
            }
            Specie editType = _SpecieRepo.GetById(specieId);

            editType.name = name;
            _SpecieRepo.Update(editType);
            return(Json(new { Result = "Success" }));
        }
예제 #3
0
        public async Task <DataResult <SpecieCreateModel> > GetSpecieById(int id)
        {
            try
            {
                Specie entity = await _specieRepository.GetById(id);

                return(new DataResult <SpecieCreateModel>
                {
                    Success = true,
                    Data = _mapper.Map(entity),
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Problems with getting Specie by id : {id}");
                return(new DataResult <SpecieCreateModel>
                {
                    Success = false,
                    ErrorCode = ErrorCode.InternalError,
                });
            }
        }