public void Add(NoticeTranslate data)
 {
     _context.Add(data);
 }
 public void Update(NoticeTranslate data)
 {
     _context.Update(data);
 }
Пример #3
0
        public async Task <IActionResult> PutAsync(int id, [FromForm] Country country)
        {
            try
            {
                country.NoticeTranslate = JsonSerializer.Deserialize <ICollection <NoticeTranslate> >(country.Notices);
                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!"
                            }
                        }
                    }));
                }
                Country db_country = _countryContext.GetWithId(id);
                if (db_country == 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 (country.Photo != null)
                {
                    ValidateModel res = country.Photo.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }

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

                    db_country.Image = fileName;
                }

                if (country.FlagPhoto != null)
                {
                    ValidateModel res = country.FlagPhoto.PhotoValidate();
                    if (!res.Success)
                    {
                        return(StatusCode(StatusCodes.Status500InternalServerError, res.Response));
                    }

                    string folder   = Path.Combine("Site", "images", "countries");
                    string fileName = await country.FlagPhoto.SaveImage(_env.WebRootPath, folder);

                    db_country.BgImage = fileName;
                }
                db_country.Name      = country.Name;
                db_country.Value     = country.Value;
                db_country.IsActived = country.IsActived;
                db_country.Wallet    = country.Wallet;
                _countryContext.Update(db_country);
                foreach (NoticeTranslate item in country.NoticeTranslate)
                {
                    NoticeTranslate db_noticeTranslate = _noticeContext.GetWithId(item.Id);
                    db_noticeTranslate.Name = item.Name;
                    _noticeContext.Update(db_noticeTranslate);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
            }
        }