Example #1
0
 public object DeleteItems([FromBody] List <int> id)
 {
     //_logger.LogInformation(LoggingEvents.LogDb, "Delete list language");
     try
     {
         for (int i = 0; i < id.Count; i++)
         {
             AdLanguage obj = new AdLanguage();
             obj.LanguageId = id[i];
             _context.AdLanguages.Attach(obj);
             _context.AdLanguages.Remove(obj);
             _context.SaveChanges();
         }
         //_logger.LogInformation(LoggingEvents.LogDb, "Delete list language successfully");
         //return Json(new JMessage() { Error = false, Title = "Delete items successfully!" });
         return(Json(new JMessage()
         {
             Error = false, Title = String.Format(CommonUtil.ResourceValue("MSG_DELETE_LIST_SUCCESS"), CommonUtil.ResourceValue("LANGUAGE"))
         }));
     }
     catch (Exception ex)
     {
         //_logger.LogError(LoggingEvents.LogDb, "Delete list language fail");
         //return Json(new JMessage() { Error = true, Title = "Delete items fail!" });
         return(Json(new JMessage()
         {
             Error = false, Title = String.Format(CommonUtil.ResourceValue("MSG_DELETE_LIST_FAIL"), CommonUtil.ResourceValue("LANGUAGE"))
         }));
     }
 }
Example #2
0
        public JsonResult Insert([FromBody] AdLanguage obj)
        {
            //_logger.LogInformation(LoggingEvents.LogDb, "Insert language ");
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var caption = _context.AdLanguages.FirstOrDefault(x => x.Culture == obj.Culture);
                if (caption == null)
                {
                    obj.CreatedDate = DateTime.Now;
                    if (obj.IsDefault == true)
                    {
                        foreach (var item in _context.AdLanguages.Where(w => w.IsDefault == true))
                        {
                            item.IsDefault = false;
                            _context.AdLanguages.Update(item);
                            _context.SaveChanges();
                        }
                    }
                    _context.AdLanguages.Add(obj);
                    var a = _context.SaveChanges();
                    //Insert Caption for language new
                    var Language = _context.AdLanguages.Where(p => p.Culture.Equals(obj.Culture)).AsNoTracking().SingleOrDefault();
                    foreach (var item in _context.AdLanguageTexts.Where(w => w.LanguageId == 1))
                    {
                        var itemLanguageNew = SetAdLanguageText(item);
                        itemLanguageNew.LanguageId = Language.LanguageId;
                        _context.AdLanguageTexts.Add(itemLanguageNew);
                    }
                    _context.SaveChanges();
                    //msg.Title = "Add item successfully";
                    msg.Title = String.Format(CommonUtil.ResourceValue("MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("LANGUAGE"));
                    //_logger.LogInformation(LoggingEvents.LogDb, "Insert language successfully");
                }
                else
                {
                    msg.Error = true;
                    //msg.Title = "Item is exists!";
                    msg.Title = String.Format(CommonUtil.ResourceValue("ERR_EXIST"), CommonUtil.ResourceValue("LANGUAGE"));
                    //_logger.LogError(LoggingEvents.LogDb, "Insert language fail");
                    return(Json(msg));
                }
            }
            catch (Exception ex)
            {
                msg.Error  = true;
                msg.Object = ex;
                //msg.Title = "Add item failed";
                msg.Title = String.Format(CommonUtil.ResourceValue("MSG_ADD_FAIL"), CommonUtil.ResourceValue("LANGUAGE"));
                //_logger.LogError(LoggingEvents.LogDb, "Insert language fail");
            }
            return(Json(msg));
        }
Example #3
0
        public JsonResult Update([FromBody] AdLanguage obj)
        {
            //_logger.LogInformation(LoggingEvents.LogDb, "Update language");
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var caption = _context.AdLanguages.FirstOrDefault(x => x.Culture == obj.Culture && x.LanguageId != obj.LanguageId);
                if (caption == null)
                {
                    if (obj.IsDefault == true)
                    {
                        foreach (var item in _context.AdLanguages.Where(w => w.IsDefault == true))
                        {
                            item.IsDefault = false;
                        }
                    }
                    _context.AdLanguages.Update(obj);
                    _context.Entry(obj).State = EntityState.Modified;
                    var a = _context.SaveChanges();
                    //msg.Title = "Update item successfully!";
                    msg.Title = String.Format(CommonUtil.ResourceValue("MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("LANGUAGE"));
                    //_logger.LogInformation(LoggingEvents.LogDb, "Update language successfully");
                }
                else
                {
                    msg.Error = true;
                    //msg.Title = "Item is exists!";
                    msg.Title = String.Format(CommonUtil.ResourceValue("ERR_EXIST"), CommonUtil.ResourceValue("LANGUAGE"));
                    //_logger.LogError(LoggingEvents.LogDb, "Update language fail");
                    return(Json(msg));
                }
            }
            catch (Exception)
            {
                msg.Error = true;
                //msg.Title = "Update item fail!";
                msg.Title = String.Format(CommonUtil.ResourceValue("MSG_UPDATE_FAIL"), CommonUtil.ResourceValue("LANGUAGE"));
                //_logger.LogError(LoggingEvents.LogDb, "Update language fail");
            }
            return(Json(msg));
        }
Example #4
0
 public void SetLanguage(AdLanguage language)
 {
     CommonUtil.CurrentLanguage = language;
 }