Exemple #1
0
        public async Task <IActionResult> AddOrEditCategoryItem(long categoryId = 0, long itemId = 0, string itemAction = "")
        {
            try
            {
                if (itemId == 0)
                {
                    BeSafeModels.MasterItemsSet masterItem = new BeSafeModels.MasterItemsSet();
                    masterItem.CategoryId  = categoryId;
                    masterItem.CreatedDate = new DateTime(2021, 01, 01);
                    return(View(masterItem));
                }
                else
                {
                    var masterItemEntity = await masterItemBusinessLogic.GetMasterItemById(itemId);

                    var masterItemModel = mapMasterItemEntityToModel.ConvertObject(masterItemEntity);

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

                    masterItemModel.itemAction = itemAction;
                    return(View(masterItemModel));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #2
0
 public async Task <IActionResult> AddOrEditCategoryItem(long ItemId, [Bind("ItemId,CreatedDate,CategoryId,ItemType,Name,Description,ItemLink,UploadFile")] BeSafeModels.MasterItemsSet masterItemsSet)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (ItemId == 0)
             {
                 var masterItem = mapMasterItemModelToEntity.ConvertObject(masterItemsSet);
                 if (masterItemsSet.UploadFile != null)
                 {
                     var uniqueFileName = Util.GetUniqueFileName(masterItemsSet.UploadFile.FileName);
                     var uploads        = Path.Combine(hostingEnvironment.WebRootPath, "UploadedMasterItem");
                     var filePath       = Path.Combine(uploads, uniqueFileName);
                     masterItemsSet.UploadFile.CopyTo(new FileStream(filePath, FileMode.Create));
                     masterItem.ItemLink = uniqueFileName;
                 }
                 //masterItem.CreatedDate = DateTime.Now;
                 masterItem.CreatedDate = masterItemsSet.CreatedDate; //he dont accept this
                 //   masterItem.CreatedDate.ToString(string.Format("{0:dd/MM/yyyy}"));
                 await masterItemBusinessLogic.AddMasterItem(masterItem);
             }
             else
             {
                 //var masterItem = await masterItemBusinessLogic.GetMasterItemById(ItemId);
                 //masterItem. = category.CategoryName;
                 //masterItem.Remarks = category.Remarks;
                 var masterItem = mapMasterItemModelToEntity.ConvertObject(masterItemsSet);
                 //var CategoryEntity = mapCategoryModelToEntity.ConvertObject(category);
                 await masterItemBusinessLogic.UpdateMasterItem(masterItem);
             }
         }
         catch (Exception)
         {
             throw;
         }
         var masterItems     = masterItemBusinessLogic.GetMasterItemsByCategoryId(masterItemsSet.CategoryId).Result;
         var masterItemsSets = mapMasterItemEntityToModel.ConvertObjectCollection(masterItems);
         return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAllMasterItem", masterItemsSets) }));
     }
     return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEditCategoryItem", masterItemsSet) }));
 }