Ejemplo n.º 1
0
        public IActionResult Add(TechnologyEntity technology, string StatusRemarks, bool isSubcategoryInQuery)
        {
            int    errorCode = 0;
            string nextID    = "";

            try
            {
                nextID = SequenceHelper.GetNextSequence(Constants.ID, Constants.TABLE_TECHNOLOGY, Constants.PADDING_TECHNOLOGYID);

                technology.RowKey = technology.RowKey + "_" + nextID;

                technology.Description = technology.Description ?? "";

                technology.Tag = InsertTag(technology.NewTag, technology.Tag);

                DuplicateCheckEntity duplicateCheck = new DuplicateCheckEntity(technology.PartitionKey, technology.SubcategoryID + "_" + technology.NameHash);

                TechnologyStatusEntity technologyStatus = GetTechnologyStatusEntity(technology.PartitionKey, nextID, technology.Status, StatusRemarks);

                TableStorageHelper.InsertBatchAsync(Constants.TABLE_TECHNOLOGY, duplicateCheck, technology, technologyStatus).Wait();
            }
            catch (Exception ex)
            {
                nextID = "";
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode, category = technology.PartitionKey, subcategory = ((isSubcategoryInQuery) ? technology.SubcategoryID : ""), technology = nextID }));
        }
Ejemplo n.º 2
0
        public IActionResult Edit(TechnologyEntity technology, string OriginalNameHash, bool isSubcategoryInQuery)
        {
            int errorCode = 0;

            try
            {
                technology.Description = technology.Description ?? "";

                technology.Tag = InsertTag(technology.NewTag, technology.Tag);

                if (OriginalNameHash.Equals(technology.NameHash))
                {
                    TableStorageHelper.MergeAsync(Constants.TABLE_TECHNOLOGY, technology).Wait();
                }
                else
                {
                    DuplicateCheckEntity duplicateCheckOriginalDelete = new DuplicateCheckEntity(technology.PartitionKey, technology.SubcategoryID + "_" + OriginalNameHash);
                    duplicateCheckOriginalDelete.ETag = "*";

                    DuplicateCheckEntity duplicateCheckNewAdd = new DuplicateCheckEntity(technology.PartitionKey, technology.SubcategoryID + "_" + technology.NameHash);

                    TableStorageHelper.BatchAsync(Constants.TABLE_TECHNOLOGY, new DuplicateCheckEntity[] { duplicateCheckOriginalDelete }, new DuplicateCheckEntity[] { duplicateCheckNewAdd }, new TechnologyEntity[] { technology }).Wait();
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode, category = technology.PartitionKey, subcategory = ((isSubcategoryInQuery) ? technology.SubcategoryID : ""), technology = technology.ID }));
        }
Ejemplo n.º 3
0
        public IActionResult Edit(UserEntity user)
        {
            int errorCode = 0;

            try
            {
                if ((HttpContext?.User?.Identity?.Name ?? "").Trim().ToLower().Equals((user?.RowKey?.Trim()?.ToLower() ?? "Q!@QQW@!")) ||
                    (HttpContext?.User?.Identity?.Name ?? "") == "sachin")
                {
                    user.ETag = "*";
                    TableStorageHelper.MergeAsync(Constants.TABLE_USER, user).Wait();

                    CacheHelper.ClearUsersCache();
                }
                else
                {
                    errorCode = Constants.ERROR_CODE_ACCESS_DENIED;
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode }));
        }
Ejemplo n.º 4
0
        public IActionResult Edit(CategoryEntity entity)
        {
            int errorCode = 0;

            try
            {
                if (CacheHelper.GetCategoryList(entity.PartitionKey).Count(cat => cat.NameHash.Equals(entity.NameHash) && !cat.ID.Equals(entity.ID)) > 0)
                {
                    errorCode = Constants.ERROR_CODE_ENTITY_ALREADY_EXISTS;
                }
                else
                {
                    TableStorageHelper.MergeAsync(Constants.TABLE_CATEGORY, entity).Wait();

                    CacheHelper.ClearCategoryListCache();
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { category = entity.PartitionKey, errorCode = errorCode }));
        }
Ejemplo n.º 5
0
        public IActionResult Add(CategoryEntity entity)
        {
            int errorCode = 0;

            try
            {
                if (CacheHelper.GetCategoryList(entity.PartitionKey).Count(cat => cat.NameHash.Equals(entity.NameHash)) > 0)
                {
                    errorCode = Constants.ERROR_CODE_ENTITY_ALREADY_EXISTS;
                }
                else
                {
                    string nextSortNumber = SequenceHelper.GetNextSequence(Constants.SORT, Constants.TABLE_CATEGORY + "_" + entity.PartitionKey, Constants.PADDING_SORT);

                    string nextID = SequenceHelper.GetNextSequence(Constants.ID, Constants.TABLE_CATEGORY, Constants.PADDING_CATEGORYID);

                    entity.RowKey = nextSortNumber + "_" + nextID;


                    TableStorageHelper.InsertOrMergeAsync(Constants.TABLE_CATEGORY, entity).Wait();

                    CacheHelper.ClearCategoryListCache();
                }
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }


            return(RedirectToAction("Index", new { category = entity.PartitionKey, errorCode = errorCode }));
        }
Ejemplo n.º 6
0
        //public IActionResult Delete(CategoryEntity entity)
        //{
        //    int errorCode = 0;

        //    try
        //    {
        //        entity.Visibility = false;
        //        TableStorageHelper.MergeAsync(Constants.TABLE_CATEGORY, entity).Wait();

        //        CacheHelper.ClearCategoryListCache();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (!TableStorageHelper.IsStorageException(ex, out errorCode))
        //        {
        //            errorCode = Constants.ERROR_CODE_COMMON;
        //        }
        //    }

        //    return RedirectToAction("Index", new { category = entity.PartitionKey, errorCode = errorCode });
        //}

        public IActionResult Sort(CategoryEntity up, CategoryEntity down)
        {
            int errorCode = 0;

            try
            {
                CategoryEntity newUp   = new CategoryEntity(up.PartitionKey, up.RowKey);
                CategoryEntity newDown = new CategoryEntity(down.PartitionKey, down.RowKey);

                up.CopyTo(newUp, false);
                down.CopyTo(newDown, false);

                string upSortNumber   = up.RowKey.Split('_')[0];
                string downSortNumber = down.RowKey.Split('_')[0];

                newUp.RowKey   = downSortNumber + "_" + newUp.ID;
                newDown.RowKey = upSortNumber + "_" + newDown.ID;

                TableStorageHelper.BatchAsync(Constants.TABLE_CATEGORY, new CategoryEntity[] { up, down }, new CategoryEntity[] { newUp, newDown }, null).Wait();

                CacheHelper.ClearCategoryListCache();
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { category = up.PartitionKey, errorCode = errorCode }));
        }
Ejemplo n.º 7
0
        public IActionResult Add(UserEntity user)
        {
            int errorCode = 0;

            try
            {
                TableStorageHelper.InsertAsync(Constants.TABLE_USER, user).Wait();

                CacheHelper.ClearUsersCache();
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode }));
        }
Ejemplo n.º 8
0
        public IActionResult UpdateStatus(TechnologyEntity technology, string StatusRemarks, bool isSubcategoryInQuery)
        {
            int errorCode = 0;

            try
            {
                technology.Description = technology.Description ?? "";

                TechnologyStatusEntity technologyStatus = GetTechnologyStatusEntity(technology.PartitionKey, technology.ID, technology.Status, StatusRemarks);

                TableStorageHelper.BatchAsync(Constants.TABLE_TECHNOLOGY, null, new TechnologyStatusEntity[] { technologyStatus }, new TechnologyEntity[] { technology }).Wait();
            }
            catch (Exception ex)
            {
                if (!TableStorageHelper.IsStorageException(ex, out errorCode))
                {
                    errorCode = Constants.ERROR_CODE_COMMON;
                }
            }

            return(RedirectToAction("Index", new { errorCode = errorCode, category = technology.PartitionKey, subcategory = ((isSubcategoryInQuery) ? technology.SubcategoryID : ""), technology = technology.ID }));
        }