示例#1
0
        public async Task <IActionResult> OnPostAddNewAsync(string ID)
        {
            if (string.IsNullOrWhiteSpace(ID))
            {
                TempData.Danger("Culture name can't be empty");
                return(LocalRedirect(Url.Page("Index", new { area = "XLocalizer" })));
            }

            var culture = new XDbCulture
            {
                ID          = ID,
                EnglishName = CultureInfo.GetCultureInfo(ID).EnglishName,
                IsDefault   = false,
                IsActive    = false
            };

            if (await _culManager.GetCultureAsync(ID) != null)
            {
                TempData.Warning("Culture already exists!");
            }

            else if (await _culManager.AddCultureAsync(culture))
            {
                TempData.Success("New culture added");
            }
            else
            {
                TempData.Danger("Culture not added!");
            }

            return(LocalRedirect(Url.Page("Index", new { area = "XLocalizer" })));
        }
示例#2
0
        /// <summary>
        /// Update a resource
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <bool> UpdateCultureAsync(XDbCulture entity)
        {
            // check if culture is being tracked
            var local = _context.Set <XDbCulture>().Local.SingleOrDefault(x => x.ID.Equals(entity.ID));

            // if entity is tracked detach it from context
            if (local != null)
            {
                _context.Entry <XDbCulture>(local).State = EntityState.Detached;
            }

            _context.Attach(entity).State = EntityState.Modified;

            return(await _context.SaveChangesAsync() > 0);
        }
示例#3
0
        /// <summary>
        /// Add new culture
        /// </summary>
        /// <param name="culture"></param>
        /// <returns></returns>
        public async Task <bool> AddCultureAsync(XDbCulture culture)
        {
            bool suscess;

            try
            {
                _context.Entry <XDbCulture>(culture).State = EntityState.Added;

                suscess = await _context.SaveChangesAsync() > 0;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                suscess = false;
            }

            return(suscess);
        }