Example #1
0
        public ActionResult assignLanguage(string userID, string code)
        {
            ajaxReturnData data = new ajaxReturnData();

            try
            {
                using (ApplicationDbContext DB = new ApplicationDbContext())
                {
                    
                    if (!DB.UserLanguages.Any(u => u.userID == userID && u.code == code))
                    {
                        UserLanguage ul = new UserLanguage();

                        ul.userID = userID;
                        ul.code = code;
                        DB.UserLanguages.Add(ul);
                        DB.SaveChanges();

                        data.statusCode = (int)statusCodes.successRun;
                        data.message = "language added to user";
                        
                    }
                    else
                    {
                        data.statusCode = (int)statusCodes.fail;
                        data.message = "Language already exists for user";

                    }

                }

            }
            catch (Exception ex)
            {

                data.statusCode = (int)statusCodes.fail;
                data.message = "Failed to add language to user; Error is: " + ex.Message;
            }
            
            return Json(data);
        }