public Language CreateEntityFromRequest(LanguageEditRequest request, Language entity)
        {
            entity.Name         = request.Name;
            entity.OriginalName = request.OriginalName;
            entity.Description  = request.Description;
            entity.IsoCode2Char = request.IsoCode2;
            entity.IsoCode3Char = request.IsoCode3;
            entity.IconUrl      = request.Icon;

            return(entity);
        }
Exemple #2
0
        public async Task <IActionResult> Edit(LanguageEditModel model)
        {
            if (model.IsNotValid())
            {
                model.SetInputModelValues();
                return(View(model));
            }

            var path = Path.Combine("images", "flags", model.IsoCode2 + ".png");
            var icon = model.Icon;

            if (icon != null)
            {
                if (icon.ContentType != "image/png")
                {
                    model.ErrorMessages.Add("please_upload_png_file");
                }
                if ((System.IO.File.Exists(path)))
                {
                    System.IO.File.Delete(path);
                }

                var fileStream = new FileStream(Path.Combine(_environment.WebRootPath, path), FileMode.Create);
                icon.CopyTo(fileStream);
                fileStream.Close();
            }

            var request = new LanguageEditRequest(CurrentUser.Id, model.LanguageUid, model.Name, model.OriginalName,
                                                  model.IsoCode2, model.IsoCode3, path, model.Description);

            var response = await _languageService.EditLanguage(request);

            if (response.Status.IsNotSuccess)
            {
                model.MapMessages(response);
                model.SetInputModelValues();
                return(View(model));
            }

            CurrentUser.IsActionSucceed = true;
            return(Redirect("/Language/List/"));
        }
        public async Task <LanguageEditResponse> EditLanguage(LanguageEditRequest request)
        {
            var response = new LanguageEditResponse();

            var currentUser = _cacheManager.GetCachedUser(request.CurrentUserId);

            if (!currentUser.IsSuperAdmin)
            {
                response.SetInvalid();
                return(response);
            }

            var language = await _languageRepository.Select(x => x.Uid == request.LanguageUid);

            if (language.IsNotExist())
            {
                response.SetInvalid();
                response.ErrorMessages.Add("language_not_found");
                return(response);
            }

            var trimName = request.Name.Trim();

            if (await _languageRepository.Any(x => (x.Name == trimName ||
                                                    x.IsoCode2Char == request.IsoCode2 ||
                                                    x.IsoCode3Char == request.IsoCode3) && x.Uid != request.LanguageUid))
            {
            }

            var updatedEntity = _languageFactory.CreateEntityFromRequest(request, language);
            var result        = await _languageRepository.Update(request.CurrentUserId, updatedEntity);

            if (result)
            {
                response.Item   = _languageFactory.CreateDtoFromEntity(updatedEntity);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
        public static LanguageEditRequest GetLanguageEditRequest()
        {
            var request = new LanguageEditRequest(CurrentUserId, UidOne, StringOne, StringOne, IsoCode2One, IsoCode3One, StringOne, StringOne);

            return(request);
        }