public DogCertificateModel Get(int dogId, int certificateId) { var dogCert = unitOfWork.DogCertificateRepository.GetByIds(dogId, certificateId); var dogCertModel = new DogCertificateModel { DogId = dogCert.DogId, Dog = new DogModel { DogId = dogCert.Dog.DogId, Name = dogCert.Dog.Name, GuideIdAndName = new IdNameModel { Id = dogCert.Dog.Guide.GuideId, Name = $"{dogCert.Dog.Guide.FirstName} {dogCert.Dog.Guide.LastName}" } }, CertificateId = dogCert.CertificateId, Certificate = new CertificateModel { CertificateId = dogCert.CertificateId, Description = dogCert.Certificate.Description, Name = dogCert.Certificate.Name, Level = dogCert.Certificate.Level, ValidThroughMonths = dogCert.Certificate.ValidThroughMonths }, AcquiredOn = dogCert.AcquiredOn }; return(dogCertModel); }
public IActionResult Put(int dogId, int certificateId, [FromBody] DogCertificateModel obj) { if (!IsCurrentUserAdmin()) { return(Forbid()); } var dogCertificate = unitOfWork.DogCertificateRepository.GetByIds(dogId, certificateId); dogCertificate.AcquiredOn = obj.AcquiredOn; unitOfWork.Commit(); return(new ObjectResult(new { dogCertificate.DogId, dogCertificate.CertificateId })); }
public List <DogCertificateModel> Get() { var dogCerts = unitOfWork.DogCertificateRepository.GetAll().ToList(); var dogCertificateModels = new List <DogCertificateModel>(); foreach (var dogCert in dogCerts) { var dogCertModel = new DogCertificateModel { DogId = dogCert.DogId, CertificateId = dogCert.CertificateId, AcquiredOn = dogCert.AcquiredOn }; dogCertificateModels.Add(dogCertModel); } return(dogCertificateModels); }
public IActionResult Post([FromBody] DogCertificateModel obj) { if (!IsCurrentUserAdmin()) { return(Forbid()); } var dogCert = new DogCertificate { DogId = obj.DogId, CertificateId = obj.CertificateId, AcquiredOn = obj.AcquiredOn }; unitOfWork.DogCertificateRepository.Insert(dogCert); unitOfWork.Commit(); return(new ObjectResult(new { dogCert.DogId, dogCert.CertificateId })); }
public ActionResult AddDogCertificate(DogCertificateModel addedDogCertificate) { if (!LoginHelper.IsAuthenticated()) { return(RedirectToAction("Login", "Account", new { returnUrl = this.Request.Url.AbsoluteUri })); } else if (!LoginHelper.IsCurrentUserAdmin()) { return(RedirectToAction("Error", "Home", new { error = "Nie masz wystarczających uprawnień by dodać certyfikat." })); } //add dogtraining client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LoginHelper.GetToken()); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress + "dogcertificates/"); addedDogCertificate.AcquiredOn = addedDogCertificate.AcquiredOn.ToUniversalTime(); var dogCertificateSerialized = JsonConvert.SerializeObject(addedDogCertificate); message.Content = new StringContent(dogCertificateSerialized, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = client.SendAsync(message).Result; // await client.SendAsync(message) if (responseMessage.IsSuccessStatusCode) //200 OK { //display info message.Dispose(); var responseData = responseMessage.Content.ReadAsStringAsync().Result; var definition = new { DogId = "", CertificateId = "" }; var ids = JsonConvert.DeserializeAnonymousType(responseData, definition); return(RedirectToAction("Index", new { dogId = ids.DogId })); //return View("Dog", responseMessage.Content); } else // msg why not ok { message.Dispose(); ViewBag.Message = responseMessage.StatusCode; return(View("Error")); } }