Пример #1
0
        public HttpResponseMessage UpdatePersoneller(PersonellerDTO pdto)
        {
            Personeller personel = db.Personeller.Where(k => k.PersonelID == pdto.PersonelID).FirstOrDefault();

            if (personel == null)
            {
                responseMessage = Request.CreateErrorResponse(HttpStatusCode.NotFound, "İlgili personel bulunamadı.");
            }

            try
            {
                PersonellerDTO.ConvertToPersonel(pdto, personel);
                db.SaveChanges();
                responseMessage = Request.CreateResponse(HttpStatusCode.OK, pdto);
                responseMessage.Headers.Location = new Uri(Url.Link("GetById", new { id = personel.PersonelID, crudstatus = CrudeStatusCode.Update }));
            }

            catch (Exception ex)
            {
                responseMessage = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
            }


            return(responseMessage);
        }
Пример #2
0
        public HttpResponseMessage AddPersoneller(PersonellerDTO pdto)
        {
            Personeller yenipersonel = PersonellerDTO.ConvertToPersonel(pdto);

            if (yenipersonel == null)
            {
                responseMessage = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Personel boş geldi");
            }

            try
            {
                db.Personeller.Add(yenipersonel);
                db.SaveChanges();
                responseMessage = Request.CreateResponse(HttpStatusCode.Created, PersonellerDTO.ConvertToPersonelDTO(yenipersonel));
                responseMessage.Headers.Location = new Uri(Url.Link("GetById", new { id = yenipersonel.PersonelID, crudstatus = CrudeStatusCode.Insert }));
            }
            catch (Exception ex)
            {
                responseMessage = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Yeni personel kaydı gerçekleştirilemedi");
            }
            return(responseMessage);
        }