Beispiel #1
0
        public async Task <JsonResult> SaveItemCategory(itemcategory itemcategory)
        {
            try
            {
                itemcategory itemCategoryModel = null;

                bool   success = false;
                string message = "";

                if (string.IsNullOrEmpty(itemcategory.ItemCategoryId.ToString()) || itemcategory.ItemCategoryId.ToString() == "0")
                {
                    itemCategoryModel                  = new itemcategory();
                    itemCategoryModel.ItemTypeId       = itemcategory.ItemTypeId;
                    itemCategoryModel.ItemCategoryName = itemcategory.ItemCategoryName;
                    itemCategoryModel.ItemTypeId       = itemcategory.ItemTypeId;
                    itemCategoryModel.CreatedBy        = "";
                    itemCategoryModel.CreatedAt        = DateTime.Now;

                    var result = await _referenceService.SaveItemCategory(itemCategoryModel);

                    success = result;
                    if (result)
                    {
                        message = "Successfully saved.";
                    }
                    else
                    {
                        message = "Error saving data. Please contact administrator.";
                    }
                }
                else
                {
                    itemCategoryModel = await _referenceService.FindItemCategoryById(itemcategory.ItemCategoryId);

                    itemCategoryModel.ItemTypeId       = itemcategory.ItemTypeId;
                    itemCategoryModel.ItemCategoryName = itemcategory.ItemCategoryName;
                    itemCategoryModel.ItemTypeId       = itemcategory.ItemTypeId;
                    itemCategoryModel.CreatedBy        = "";
                    itemCategoryModel.CreatedAt        = DateTime.Now;

                    var result = await _referenceService.UpdateItemCategory(itemCategoryModel);

                    success = result;
                    if (result)
                    {
                        message = "Successfully updated.";
                    }
                    else
                    {
                        message = "Error saving data. Please contact administrator.";
                    }
                }

                return(Json(new { success = success, message = message }));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #2
0
        public async Task <bool> UpdateItemCategory(itemcategory model)
        {
            try
            {
                using (var uow = _unitOfWorkFactory.Create())
                {
                    var result = await FindItemCategoryById(model.ItemCategoryId);

                    if (result != null)
                    {
                        uow.ItemCategoryRepository.Update(model);
                        await uow.SaveChangesAsync();

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }