Esempio n. 1
0
        public async Task <CategoryMappingModel> CreateCategoryMappingForCurrentUser(CategoryMappingModel model)
        {
            var userId = await _authenticationService.GetCurrentUserId();

            using var unitOfWork = _unitOfWork();

            var existingCategoryMapping = await unitOfWork.CategoryMappingRepository.FindSingle(findQuery : x =>
                                                                                                x.ColumnTypeId == model.ColumnTypeId &&
                                                                                                x.CategoryId == model.CategoryId &&
                                                                                                x.UserId == userId);

            if (existingCategoryMapping?.MatchValue.Equals(model.MatchValue, StringComparison.InvariantCultureIgnoreCase) == true)
            {
                throw new AlreadyExistsException(nameof(CategoryMappingEntity));
            }

            var entity = model.ToNewEntity(userId);

            unitOfWork.CategoryMappingRepository.Insert(entity);

            await unitOfWork.SaveAsync();

            var insertedCategoryMapping = await FindCategoryMapping(entity.Id, userId, unitOfWork);

            return(insertedCategoryMapping.ToDto());
        }
Esempio n. 2
0
        public ActionResult GetCategoryUserMapping(string Id)
        {
            CategoryMappingModel model;

            // var res="";

            if (!string.IsNullOrEmpty(Id))
            {
                var Tablelst = _subCategoryService.GetCategoryUserMappingList();
                var res      = _subCategoryService.GetCategoryUserMapping(Convert.ToDecimal(Id));
                model = new CategoryMappingModel
                {
                    ID                   = Convert.ToInt32(res.ID),
                    UserID               = res.UserID ?? 0,
                    FirstName            = res.UserFirstName,
                    LastName             = res.UserLastName,
                    CategoryId           = res.CategoryID ?? 0,
                    CategoryName         = res.CategoryName,
                    Logintbllst          = Tablelst.Item1,
                    SubCategoryMasterlst = Tablelst.Item2
                };
                //model = AutoMapper.Mapper.Map<CategoryUserMapping, CategoryMappingModel>(res);
            }
            else
            {
                model = new CategoryMappingModel();
                //model = new CategoryMappingModel();
            }
            return(Json(RenderRazorViewToString("AddEditCategoryMapp", model), JsonRequestBehavior.AllowGet));

            //ViewBag.CategoryList = _categoryMasterService.GetCategoryList();
            //return RedirectToAction("CategoryUserMappingList", model);
        }
 public static CategoryMappingEntity ToNewEntity(this CategoryMappingModel model, int userId)
 {
     return(new CategoryMappingEntity
     {
         CategoryId = model.CategoryId,
         ColumnTypeId = model.ColumnTypeId,
         MatchValue = model.MatchValue,
         UserId = userId
     });
 }
Esempio n. 4
0
        public ActionResult CategoryUserMappingList()
        {
            var res       = _subCategoryService.GetCategoryUserMappingList();
            var res1      = _subCategoryService.GetCategoryUserMappingGrid();
            var viewModel = new CategoryMappingModel
            {
                Logintbllst          = res.Item1,
                SubCategoryMasterlst = res.Item2,
                CategoryUserMapping  = res1
            };

            return(View(viewModel));
        }
Esempio n. 5
0
        public ActionResult AddCategoryUserMapping(CategoryMappingModel model)
        {
            // var res = AutoMapper.Mapper.Map<CategoryMappingModel, CategoryUserMapping>(model);

            var isSuccess = _subCategoryService.AddCategoryUserMapping(new CategoryUserMapping {
                ID         = model.ID,
                CategoryID = model.CategoryId,
                UserID     = model.UserID
            });

            return(Json(isSuccess, JsonRequestBehavior.AllowGet));
            //return RedirectToAction("CategoryUserMapping");
        }
Esempio n. 6
0
        /// <summary>
        /// Upserts a category mapping to the database
        /// </summary>
        /// <param name="model">Model to upsert</param>
        /// <returns>Result of the upsert</returns>
        public async Task <IActionResult> UpsertCategoryMapping(CategoryMappingModel model)
        {
            if (ModelState.IsValid)
            {
                // Placeholder extra validation, in the future all mappings should be possible
                if (model.ColumnTypeId != ColumnType.Description &&
                    model.ColumnTypeId != ColumnType.Name &&
                    model.ColumnTypeId != ColumnType.DestinationAccount)
                {
                    ModelState.AddModelError("", Resources.UnsupportedColumnTypeMapping);
                    return(PartialView("UpsertCategoryMapping", model));
                }

                if (model.Id > 0)
                {
                    try
                    {
                        await _categoryMappingService.UpdateCategoryMappingForCurrentUser(model);

                        return(Json(new SinanceJsonResult
                        {
                            Success = true
                        }));
                    }
                    catch (NotFoundException)
                    {
                        TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryMappingNotFound);
                        return(PartialView("UpsertCategoryMapping", model));
                    }
                }
                else
                {
                    try
                    {
                        await _categoryMappingService.CreateCategoryMappingForCurrentUser(model);

                        return(Json(new SinanceJsonResult
                        {
                            Success = true
                        }));
                    }
                    catch (NotFoundException)
                    {
                        TempDataHelper.SetTemporaryMessage(TempData, MessageState.Error, Resources.CategoryNotFound);
                        return(PartialView("UpsertCategoryMapping", model));
                    }
                }
            }

            return(PartialView("UpsertCategoryMapping", model));
        }
Esempio n. 7
0
        public CategoryMappingViewModel()
        {
            reportService    = new ReportService();
            SelectedCategory = new CategoryMappingModel();
            CategoryMappings = new ObservableRangeCollection <CategoryMapping>();
            BindData();

            ResetCommand       = new BaseCommand(ResetFields);
            FindCommand        = new BaseCommand(FindData);
            AddNewCommand      = new BaseCommand(AddNewRecord);
            ClosePopupCommand  = new BaseCommand(ClosePopup);
            SaveCommand        = new BaseCommand(CanSave, SaveData);
            RowSelectedCommand = new BaseCommand(RowSelected);
            UpdateCommand      = new BaseCommand(CanUpdate, UpdateData);
        }
        public async Task <CategoryMappingModel> UpdateCategoryMappingForCurrentUser(CategoryMappingModel model)
        {
            using var unitOfWork = _unitOfWork();

            var existingCategoryMapping = await FindCategoryMapping(model.Id, unitOfWork);

            if (existingCategoryMapping == null)
            {
                throw new NotFoundException(nameof(CategoryMappingEntity));
            }

            existingCategoryMapping.UpdateEntityFromModel(model);
            await unitOfWork.SaveAsync();

            return(existingCategoryMapping.ToDto());
        }
Esempio n. 9
0
        /// <summary>
        /// Rows the selected.
        /// </summary>
        /// <param name="selectedRow">The selected row.</param>
        private void RowSelected(object selectedRow)
        {
            CategoryMapping selectedCategoryRow = selectedRow as CategoryMapping;

            if (selectedCategoryRow == null)
            {
                return;
            }
            SelectedCategory = new CategoryMappingModel
            {
                EventCategory = selectedCategoryRow.EventCategoryId,
                ExceptionType = selectedCategoryRow.ExceptionType,
                Id            = selectedCategoryRow.Id
            };
            ShowPopup = true;
        }
        public static CategoryMappingEntity UpdateEntityFromModel(this CategoryMappingEntity entity, CategoryMappingModel model)
        {
            entity.MatchValue   = model.MatchValue;
            entity.ColumnTypeId = model.ColumnTypeId;
            entity.CategoryId   = model.CategoryId;

            return(entity);
        }
Esempio n. 11
0
 /// <summary>
 /// Adds the new record.
 /// </summary>
 private void AddNewRecord()
 {
     SelectedCategory = new CategoryMappingModel();
     ShowPopup        = true;
 }