public void Update(ServiceTranslate data)
 {
     _context.Update(data);
 }
        public async Task <IActionResult> PutAsync(int id, [FromForm] Service service)
        {
            try
            {
                service.ServiceTranslates = JsonSerializer.Deserialize <ICollection <ServiceTranslate> >(service.Translates);
                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                Service db_service = _serviceContext.GetWithId(id);
                if (db_service == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                    {
                        Status = "Error",
                        Messages = new Message[] {
                            new Message {
                                Lang_id = 1,
                                MessageLang = "Model state isn't valid!"
                            },
                            new Message {
                                Lang_id = 2,
                                MessageLang = "Состояние модели недействительно!"
                            },
                            new Message {
                                Lang_id = 3,
                                MessageLang = "Model vəziyyəti etibarsızdır!"
                            }
                        }
                    }));
                }
                if (service.Photo != null)
                {
                    ValidateModel res = service.Photo.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }

                    string folder   = Path.Combine("Site", "images", "serviceIcon");
                    string fileName = await service.Photo.SaveImage(_env.WebRootPath, folder);

                    db_service.Image = fileName;
                }
                db_service.IsActived = service.IsActived;

                _serviceContext.Update(db_service);
                foreach (ServiceTranslate item in service.ServiceTranslates)
                {
                    ServiceTranslate db_Translate = _serviceTranslateContext.GetWithId(item.Id);
                    db_Translate.Title       = item.Title;
                    db_Translate.Description = item.Description;
                    _serviceTranslateContext.Update(db_Translate);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }
 public void Add(ServiceTranslate data)
 {
     _context.Add(data);
 }