Esempio n. 1
0
        public async Task <ResponceModel> Update([FromRoute] int id, [FromBody] CityDTO model)
        {
            var identifier = User.Claims.FirstOrDefault(p => p.Type == "id");

            if (identifier == null)
            {
                return(new ResponceModel(401, "Unauthorized", null, new string[] { "Yetkilendirme Hatası." }));
            }
            if (id == 0)
            {
                return(new ResponceModel(404, "ERROR", null, new string[] { "Gönderilecek model bulunamadı" }));
            }
            try
            {
                var city = await cityService.Get(id);

                if (city == null)
                {
                    return(new ResponceModel(404, "ERROR", null, new string[] { "Gönderilecek model bulunamadı" }));
                }
                city = model.Adapt <City>();
                cityService.Update(city);
                if (await cityService.SaveChangesAsync())
                {
                    return(new ResponceModel(200, "OK", city, null));
                }
                else
                {
                    return(new ResponceModel(500, "ERROR", null, new string[] { "Gönderi güncellenirken bir hata oluştu." }));
                }
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = cityService.GetType().Name
                });

                return(new ResponceModel(500, "ERROR", null, new string[] { "Gönderi güncellenirken bir hata oluştu." }));
            }
        }
Esempio n. 2
0
 public async Task UpdateCityAsync(CityDTO city)
 {
     db.CityRepository.Update(city.Adapt <City>());
     await db.Save();
 }
Esempio n. 3
0
 public async Task AddCityAsync(CityDTO city)
 {
     db.CityRepository.Add(city.Adapt <City>());
     await db.Save();
 }