Пример #1
0
        public async Task <IActionResult> GetMaterialType()
        {
            try
            {
                if (_cache.TryGetValue("CACHE_MASTER_MATERIALTYPE", out List <M_MaterialType> c_lstMatType))
                {
                    return(Json(new { data = c_lstMatType }));
                }

                MemoryCacheEntryOptions options = new MemoryCacheEntryOptions
                {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(300),
                    SlidingExpiration = TimeSpan.FromSeconds(60),
                    Priority          = CacheItemPriority.NeverRemove
                };

                using (var matTypeBll = new MaterialTypeBLL())
                {
                    var lstMatType = await matTypeBll.GetMaterialType(null);

                    _cache.Set("CACHE_MASTER_MATERIALTYPE", lstMatType, options);

                    return(Json(new { data = lstMatType }));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, message = ex.Message }));
            }

            //using (var matTypeBll = new MaterialTypeBLL())
            //{
            //    return Json(new { data = await matTypeBll.GetMaterialType(null) });
            //}
        }
Пример #2
0
        public async Task <IActionResult> DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ResultObject resultObj;

            try
            {
                if (_cache.TryGetValue("CACHE_MASTER_MATERIALTYPE", out List <M_MaterialType> c_lstMatType))
                {
                    var m_MaterialType = c_lstMatType.Find(m => m.Id == id);

                    if (m_MaterialType == null)
                    {
                        return(NotFound());
                    }

                    m_MaterialType.Updated_By = await base.CurrentUserId();

                    using (var matTypeBll = new MaterialTypeBLL())
                    {
                        resultObj = await matTypeBll.DeleteMaterialType(m_MaterialType);

                        _cache.Remove("CACHE_MASTER_MATERIALTYPE");
                    }

                    return(Json(new { success = true, data = (M_MaterialType)resultObj.ObjectValue, message = "Material Type Deleted." }));
                }

                using (var matTypeBll = new MaterialTypeBLL())
                {
                    var lstMatType = await matTypeBll.GetMaterialType(id);

                    var m_MaterialType = lstMatType.First();

                    if (m_MaterialType == null)
                    {
                        return(NotFound());
                    }

                    m_MaterialType.Updated_By = await base.CurrentUserId();

                    resultObj = await matTypeBll.DeleteMaterialType(m_MaterialType);

                    _cache.Remove("CACHE_MASTER_MATERIALTYPE");
                }

                return(Json(new { success = true, data = (M_MaterialType)resultObj.ObjectValue, message = "Material Type Deleted." }));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }));
            }
        }
Пример #3
0
        // GET: Master/MaterialType/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ViewBag.CompCode = await base.CurrentUserComp();

            try
            {
                if (_cache.TryGetValue("CACHE_MASTER_MATERIALTYPE", out List <M_MaterialType> c_lstMatType))
                {
                    var m_MaterialType = c_lstMatType.Find(m => m.Id == id);

                    if (m_MaterialType == null)
                    {
                        return(NotFound());
                    }

                    return(PartialView(m_MaterialType));
                }

                using (var matTypeBll = new MaterialTypeBLL())
                {
                    var lstMatType = await matTypeBll.GetMaterialType(id);

                    var m_MaterialType = lstMatType.First();

                    if (m_MaterialType == null)
                    {
                        return(NotFound());
                    }

                    return(PartialView(m_MaterialType));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, message = ex.Message }));
            }
        }