Exemplo n.º 1
0
        public ActionResult AddLanguage([FromBody] AddLanguageViewModel language)
        {
            //Your code here;
            if (ModelState.IsValid)
            {
                if (_profileService.AddNewLanguage(language))
                {
                    return(Json(new { Success = true }));
                }
            }
            return(Json(new { Success = false }));


            //try
            //{
            //    var languageResult = await _profileService.AddNewLanguage(language);
            //    //var languageResult = await _profileService.AddNewLanguage(language);

            //    if (languageResult == false)
            //    {
            //        return Json(new { success = false, data = "can not add the language." });

            //    }

            //    return Json(new { Success = true, data = "add successful" });

            //}

            //catch (Exception e)
            //{
            //    return Json(new { success = false, data = "error" });
            //}
        }
Exemplo n.º 2
0
        public bool AddNewLanguage(AddLanguageViewModel language)
        {
            //Your code here;

            throw new NotImplementedException();

            //try
            //{
            //    var userId = _userAppContext.CurrentUserId;
            //    User userProfile = await _userRepository.GetByIdAsync(userId);
            //    if (userProfile == null)
            //    {
            //        return false;
            //    }
            //    var newLanguage = new UserLanguage
            //    {
            //        Id = ObjectId.GenerateNewId().ToString(),
            //        IsDeleted = false,
            //        UserId = userId
            //    };
            //    UpdateLangFromView(language, newLanguage);
            //    userProfile.Languages.Add(newLanguage);

            //    await _userRepository.Update(userProfile);
            //    return true;
            //}
            //catch (MongoException e)
            //{
            //    return false;
            //}
        }
Exemplo n.º 3
0
        public bool AddNewLanguage(AddLanguageViewModel language)
        {
            String id       = " ";
            String talentId = String.IsNullOrWhiteSpace(id) ? _userAppContext.CurrentUserId : id;

            try
            {
                var lang = new UserLanguage
                {
                    Id            = ObjectId.GenerateNewId().ToString(),
                    UserId        = _userAppContext.CurrentUserId,
                    Language      = language.Name,
                    LanguageLevel = language.Level,
                    IsDeleted     = false
                };
                var user = _userRepository.GetByIdAsync(talentId).Result;
                user.Languages.Add(lang);
                _userRepository.Update(user);
                return(true);
            }
            catch (MongoException e)
            {
                return(false);
            }
        }
 public ActionResult AddLanguage([FromBody] AddLanguageViewModel language)
 {
     //Your code here;
     // TODO: Add language
     _profileService.AddNewLanguage(language);
     return(Json(new { Success = true }));
 }
Exemplo n.º 5
0
 public ActionResult AddLanguage([FromBody] AddLanguageViewModel language)
 {
     //Your code here;
     //throw new NotImplementedException();
     {
         if (ModelState.IsValid)
         {
             String id          = " ";
             String talentId    = String.IsNullOrWhiteSpace(id) ? _userAppContext.CurrentUserId : id;
             var    addLanguage = new UserLanguage
             {
                 Id            = ObjectId.GenerateNewId().ToString(),
                 UserId        = _userAppContext.CurrentUserId,
                 Language      = language.Name,
                 LanguageLevel = language.Level,
                 IsDeleted     = false
             };
             var user = _userRepository.GetByIdAsync(talentId).Result;
             user.Languages.Add(addLanguage);
             _userRepository.Update(user);
             return(Json(new { Success = true }));
         }
         return(Json(new { Success = false }));
     }
 }
Exemplo n.º 6
0
        public IActionResult AddLanguage(AddLanguageViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Identifier.Length == 2)
                {
                    var response = _localizationService.AddLanguage(model);
                    if (response.IsSuccess)
                    {
                        return(RedirectToAction("GetLanguages", "Localization"));
                    }

                    foreach (var e in response.Errors)
                    {
                        ModelState.AddModelError(e.Key, e.Message);
                    }

                    return(View(model));
                }

                ModelState.AddModelError(string.Empty, "Identifier must have only 2 characters");
                return(View(model));
            }

            ModelState.AddModelError(string.Empty, "Something is not right");

            return(View(model));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> DeleteLanguage([FromBody] AddLanguageViewModel language)
        {
            language.IsDeleted = true;
            var id = await _profileService.AddUpdateLanguage(language);

            return(Json(new { Id = id }));
        }
        public bool AddNewLanguage(AddLanguageViewModel language)
        {
            //if language is not same return true

            //Your code here;
            throw new NotImplementedException();
        }
        public async Task <bool> UpdateLanguage(AddLanguageViewModel language)
        {
            try
            {
                var  userId      = _userAppContext.CurrentUserId;
                User userProfile = await _userRepository.GetByIdAsync(userId);

                if (userProfile == null)
                {
                    return(false);
                }
                var orginalLanguage = userProfile.Languages.SingleOrDefault(x => x.Id == language.Id);
                if (orginalLanguage == null)
                {
                    return(false);
                }
                UpdateLanguageFromView(language, orginalLanguage);
                await _userRepository.Update(userProfile);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public async Task <bool> AddNewLanguage(AddLanguageViewModel language)
        {
            try
            {
                var  userId      = _userAppContext.CurrentUserId;
                User userProfile = await _userRepository.GetByIdAsync(userId);

                if (userProfile == null)
                {
                    return(false);
                }

                var newLanguage = new UserLanguage
                {
                    Id        = ObjectId.GenerateNewId().ToString(),
                    IsDeleted = false,
                    UserId    = userId
                };
                UpdateLanguageFromView(language, newLanguage);
                userProfile.Languages.Add(newLanguage);
                await _userRepository.Update(userProfile);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 11
0
        //This piece of code is working fine, but set isDeleted to true will not delete target row
        public async Task <bool> EditLanguage(string userId, AddLanguageViewModel language)
        {
            try
            {
                if (userId != null)
                {
                    User currentTalent = (await _userRepository.GetByIdAsync(userId));

                    //var newlanguage = new list<userlanguage>();


                    currentTalent.Languages.SingleOrDefault(x => x.Id == language.Id).Language      = language.Name;
                    currentTalent.Languages.SingleOrDefault(x => x.Id == language.Id).LanguageLevel = language.Level;

                    //updatelanguagefromview(item, targetlanguage);
                    //newlanguage.add(targetlanguage);

                    //currenttalent.languages = newlanguage;


                    await _userRepository.Update(currentTalent);

                    return(true);
                }
                return(false);
            }

            catch (MongoException)
            {
                return(false);
            }
        }
Exemplo n.º 12
0
        public async Task <ActionResult> UpdateLanguage([FromBody] AddLanguageViewModel language)
        {
            try
            {
                var myLanguage = await _userLanguageRepository.GetByIdAsync(language.Id);


                if (myLanguage != null)
                {
                    myLanguage.LanguageLevel = language.Level;
                    myLanguage.Language      = language.Name;
                    myLanguage.Id            = language.Id;
                    myLanguage.IsDeleted     = false;
                }
                else
                {
                    return(Json(new { Success = false, Message = "could not update" }));
                }

                await _userLanguageRepository.Update(myLanguage);


                return(Json(new { Success = true, Message = "language updated succesfully" }));
            }
            catch
            {
                return(Json(new { Success = false, Message = "Error while updating language" }));
            }
        }
Exemplo n.º 13
0
        public async Task <bool> AddNewLanguageAsync(AddLanguageViewModel language)
        {
            try
            {
                if (language != null)
                {
                    var newLanguage = new UserLanguage
                    {
                        Id        = ObjectId.GenerateNewId().ToString(),
                        IsDeleted = false
                    };

                    UpdateLanguageFromView(language, newLanguage);


                    await _userLanguageRepository.Add(newLanguage);

                    return(true);
                }
                return(false);
            }
            catch (MongoException e)
            {
                return(false);
            }
        }
Exemplo n.º 14
0
        public async Task <ActionResult> DeleteLanguage([FromBody] AddLanguageViewModel language)
        {
            //Your code here;
            // throw new NotImplementedException();
            try
            {
                var userId = _userAppContext.CurrentUserId;
                var dUser  = await _userRepository.GetByIdAsync(userId);

                if (dUser != null)
                {
                    var findLanguageItem = dUser.Languages.SingleOrDefault(x => x.Id == language.Id);
                    if (findLanguageItem != null)
                    {
                        findLanguageItem.IsDeleted = true;
                        dUser.Languages[dUser.Languages.FindIndex(x => x.Id == language.Id)] = findLanguageItem;
                        await _userRepository.Update(dUser);

                        return(Json(new { Success = true }));
                    }
                    else
                    {
                        return(Json(new { Success = false, Message = "The language is not existing" }));
                    }
                }
                else
                {
                    return(Json(new { Success = false, Message = "The user is not existing" }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { Message = "Error in deleting" }));
            }
        }
        public async Task <ActionResult> DeleteLanguage([FromBody] AddLanguageViewModel delete_language_model, String id = "")
        {
            //Your code here;
            String talentId = String.IsNullOrWhiteSpace(id) ? _userAppContext.CurrentUserId : id;

            if (talentId != null)
            {
                User existingTalent = (await _userRepository.GetByIdAsync(talentId));
                var  newLanguages   = new List <UserLanguage>();
                foreach (var item in existingTalent.Languages)
                {
                    var delete_language = existingTalent.Languages.SingleOrDefault(x => x.Id == delete_language_model.Id);
                    if (item.Id != delete_language_model.Id)
                    {
                        newLanguages.Add(item);
                    }
                }
                existingTalent.Languages = newLanguages;
                existingTalent.UpdatedBy = talentId;
                existingTalent.UpdatedOn = DateTime.Now;
                await _userRepository.Update(existingTalent);

                User UpdateTalent = (await _userRepository.GetByIdAsync(talentId));
                return(Json(new { success = true, data = existingTalent }));
            }
            return(Json(new { success = false }));
        }
Exemplo n.º 16
0
        public async Task <bool> AddNewLanguage(AddLanguageViewModel language, string updaterId)
        {
            //  UserLanguage existingUser = null;



            try
            {
                if (language.Id != null)
                {
                    UserLanguage existingUser = (await _userLanguageRepository.GetByIdAsync(language.Id));
                    existingUser.Language      = language.Name;
                    existingUser.LanguageLevel = language.Level;


                    await _userLanguageRepository.Update(existingUser);

                    return(true);
                }
                return(false);
            }
            catch (MongoException e)
            {
                return(false);
            }
        }
Exemplo n.º 17
0
        public async Task <ActionResult> UpdateLanguage([FromBody] AddLanguageViewModel language)
        {
            //Your code here;
            // throw new NotImplementedException();
            try
            {
                User userProfile = await _userRepository.GetByIdAsync(language.CurrentUserId);

                var orginal = userProfile.Languages.SingleOrDefault(x => x.Id == language.Id);

                if (userProfile != null)
                {
                    orginal.LanguageLevel = language.Level;
                    orginal.Language      = language.Name;
                    orginal.Id            = language.Id;
                    orginal.IsDeleted     = false;
                }
                else
                {
                    return(Json(new { Success = false, Message = "Language is not updated." }));
                }

                await _userRepository.Update(userProfile);


                return(Json(new { Success = true, Message = "Language is succesfully updated" }));
            }
            catch
            {
                return(Json(new { Success = false, Message = "Error in updating language" }));
            }
        }
Exemplo n.º 18
0
        public ActionResult AddLanguage([FromBody] AddLanguageViewModel language)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    String id          = "";
                    String talentId    = String.IsNullOrWhiteSpace(id) ? _userAppContext.CurrentUserId : id;
                    var    addLanguage = new UserLanguage
                    {
                        Id            = ObjectId.GenerateNewId().ToString(),
                        UserId        = _userAppContext.CurrentUserId,
                        Language      = language.Name,
                        LanguageLevel = language.Level,
                        IsDeleted     = false
                    };
                    var result = _userRepository.GetByIdAsync(talentId).Result;
                    result.Languages.Add(addLanguage);
                    _userRepository.Update(result);
                    return(Json(new { Success = true }));
                }

                return(Json(new { Success = false }));
            }
            catch (Exception e)
            {
                return(Json(new { Success = false, e.Message }));
            }
        }
Exemplo n.º 19
0
        public ActionResult AddLanguage([FromBody] AddLanguageViewModel language)
        {
            //try
            //{

            //    if (ModelState.IsValid)
            //    {

            //        if (_profileService.UpdateTalentProfile())
            //        {

            //        }

            //    }
            //    return Json(new { Success = false });
            //}
            //catch (Exception e)
            //{
            //    return Json(new { Success = false, message = e });
            //}



            throw new NotImplementedException();
        }
Exemplo n.º 20
0
 public async Task <ActionResult> UpdateLanguage([FromBody] AddLanguageViewModel language)
 {
     try
     {
         if (ModelState.IsValid)
         {
             String id       = "";
             String talentId = String.IsNullOrWhiteSpace(id) ? _userAppContext.CurrentUserId : id;
             var    result   = _userRepository.GetByIdAsync(talentId).Result;
             if (language.Id != null)
             {
                 var updateLanguage = result.Languages.SingleOrDefault(x => x.Id == language.Id);
                 {
                     updateLanguage.Language      = language.Name;
                     updateLanguage.LanguageLevel = language.Level;
                 }
                 await _userRepository.Update(result);
             }
             return(Json(new { Success = true }));
         }
         return(Json(new { Success = false }));
     }
     catch (Exception e)
     {
         return(Json(new { Success = false, e.Message }));
     }
 }
        public async Task <ActionResult> DeleteLanguage([FromBody] AddLanguageViewModel language)
        {
            //Your code here;
            // TODO: Delete language
            await _profileService.DeleteLanguageAsync(language);

            return(Json(new { Success = true }));
        }
        public bool getLanguage(AddLanguageViewModel language)
        {
            //_userLanguageRepository
            //Your code here;


            throw new NotImplementedException();
        }
Exemplo n.º 23
0
        public ActionResult AddLanguage([FromBody] AddLanguageViewModel language)
        {
            String talentId    = _userAppContext.CurrentUserId;
            var    newLanguage = language;

            newLanguage.CurrentUserId = talentId;
            //var userProfile = await _profileService.GetTalentProfile(talentId);

            return(Json(new { Success = true }));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Add language
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddLanguage(AddLanguageViewModel model)
        {
            var existsInConfig =
                _locConfig.Value.Languages.Any(m => m.Identifier == model.Identifier && m.Name == model.Name);

            var cPaths = new[]
            {
                _env.ContentRootPath,
                _locConfig.Value.Path,
                $"{model.Identifier}.json"
            };

            var filePath   = Path.Combine(cPaths);
            var fileExists = File.Exists(filePath);

            if (existsInConfig || fileExists)
            {
                return(false);
            }

            using (Stream stream =
                       new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
                using (var sWriter = new StreamWriter(stream))
                    using (var writer = new JsonTextWriter(sWriter))
                    {
                        var keys = _localizer.GetAllForLanguage("en").Select(ls => ls.Name);
                        var dict = keys.ToDictionary <string, string, string>(key => key, key => null);
                        var obj  = JObject.FromObject(dict);

                        writer.Formatting = Formatting.Indented;
                        obj.WriteTo(writer);
                    }

            var langFile = _env.ContentRootFileProvider.GetFileInfo("appsettings.json");

            using (Stream str = new FileStream(langFile.PhysicalPath, FileMode.Open, FileAccess.Read,
                                               FileShare.ReadWrite))
                using (var sReader = new StreamReader(str))
                    using (var reader = new JsonTextReader(sReader))
                    {
                        var fileObj = JObject.Load(reader);
                        _locConfig.Value.Languages.Add(new LanguageCreateViewModel
                        {
                            Identifier = model.Identifier,
                            Name       = model.Name,
                            IsDisabled = false
                        });
                        var newLangs = JArray.FromObject(_locConfig.Value.Languages);
                        fileObj[nameof(LocalizationConfig)][nameof(LocalizationConfig.Languages)] = newLangs;
                        reader.Close();
                        File.WriteAllText(langFile.PhysicalPath, fileObj.ToString());
                    }

            return(true);
        }
 // Nik custom code
 protected UserLanguage LanguageFromViewModel(AddLanguageViewModel model)
 {
     return(new UserLanguage
     {
         Id = model.Id,
         UserId = model.CurrentUserId,
         Language = model.Name,
         LanguageLevel = model.Level,
         IsDeleted = false,
     });
 }
Exemplo n.º 26
0
        public IActionResult Index()
        {
            var addLanguageViewModel = new AddLanguageViewModel
            {
                LanguageLevels = jobSeekerService.GetLanguageLevel(),
                Languages      = languageService.GetAll(),
                JobSeekerLanguagesViewModel = jobSeekerService.GetJobSeekerLanguages(HttpContext.Session.Get <string>("JobSeekerId"))
            };

            return(View(addLanguageViewModel));
        }
Exemplo n.º 27
0
        public bool AddNewLanguage(AddLanguageViewModel language)
        {
            //Your code here;
            //throw new NotImplementedException();
            var newLanguages = new List <AddLanguageViewModel>();


            newLanguages.Add(language);

            // _userRepository.Add(language);
            return(true);
        }
 public ActionResult AddLanguage([FromBody] AddLanguageViewModel language)
 {
     {
         if (ModelState.IsValid)
         {
             if (_profileService.AddNewLanguage(language))
             {
                 return(Json(new { Success = true }));
             }
         }
         return(Json(new { Success = false }));
     }
 }
Exemplo n.º 29
0
        public ActionResult DeleteLanguage(AddLanguageViewModel language)
        {
            var existingLanguage = _personLanguageRepository.GetById(language.Id);

            if (existingLanguage.PersonId != _appContext.LoginId)
            {
                return(new JsonCamelCaseResult(new { Success = false, Message = "You are not allowed to delete this language" }, JsonRequestBehavior.AllowGet));
            }

            _personLanguageRepository.Delete(existingLanguage);

            return(new JsonCamelCaseResult(new { Success = true, existingLanguage.Language }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 30
0
        public async Task <string> AddUpdateLanguage(AddLanguageViewModel language)
        {
            if (language.Id != null && language.Id != "")
            {
                var languageInDb = await _userLanguageRepository.GetByIdAsync(language.Id);

                languageInDb.Language      = language.Name;
                languageInDb.LanguageLevel = language.Level;
                languageInDb.IsDeleted     = language.IsDeleted;
                await _userLanguageRepository.Update(languageInDb);


                //var user = await _userRepository.GetByIdAsync(_userAppContext.CurrentUserId);
                //var userLanguageInDB = user.Languages.Single(l => l.Id == languageInDb.Id);
                //userLanguageInDB.Language = language.Name;
                //userLanguageInDB.LanguageLevel = language.Level;
                //userLanguageInDB.IsDeleted = language.IsDeleted;

                //user.Languages.Add(userLanguageInDB);

                //await _userRepository.Update(user);

                var user = await _userRepository.GetByIdAsync(_userAppContext.CurrentUserId);

                var userLanguageInDB = user.Languages.Single(l => l.Id == languageInDb.Id); //find original user language
                userLanguageInDB.Language      = languageInDb.Language;
                userLanguageInDB.LanguageLevel = languageInDb.LanguageLevel;
                userLanguageInDB.IsDeleted     = languageInDb.IsDeleted;
                user.Languages.Add(userLanguageInDB);
                await _userRepository.Update(user);

                return(language.Id);
            }
            else //create
            {
                var newLanguage = new UserLanguage()
                {
                    Language      = language.Name,
                    LanguageLevel = language.Level,
                    UserId        = _userAppContext.CurrentUserId
                };
                await _userLanguageRepository.Add(newLanguage);

                var user = await _userRepository.GetByIdAsync(_userAppContext.CurrentUserId);

                user.Languages.Add(newLanguage);
                await _userRepository.Update(user);

                return(newLanguage.Id);
            }
        }