Пример #1
0
        public async Task <ResponceModel> Update([FromRoute] int id, [FromBody] District model)
        {
            var identifier = User.Claims.FirstOrDefault(p => p.Type == "id");

            if (identifier == null)
            {
                return(new ResponceModel(401, "FAILED", null, new string[] { "Yetkilendirme Hatası." }));
            }
            if (id == 0)
            {
                return(new ResponceModel(404, "FAILD", null, new string[] { "İlçe güncellenirken bir sorun oluştu." }));
            }
            try
            {
                var district = await districtService.Get(id);

                if (district == null)
                {
                    return(new ResponceModel(404, "FAILD", null, new string[] { "İlçe güncellenirken bir sorun oluştu." }));
                }
                district = model.Adapt <District>();
                districtService.Update(model);
                if (await districtService.SaveChanges())
                {
                    return(new ResponceModel(200, "OK", district, null));
                }
                else
                {
                    return(new ResponceModel(400, "FAILD", null, new string[] { "İlçe güncellenirken bir sorun oluştu." }));
                }
            }
            catch (Exception ex)
            {
                await _logService.Add(new SystemLog()
                {
                    Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = districtService.GetType().Name
                });

                return(new ResponceModel(500, "ERROR", null, new string[] { "İlçe güncellenirken bir sorun oluştu." }));
            }
        }