public async Task Create(ReferenceDto input)
        {
            switch (input.Type)
            {
            case ReferenceEnum.Category:
                await _categoryRepository.InsertAsync(new Category { Name = input.Name });

                break;

            case ReferenceEnum.SubCategory:
                var newSubCategoryId = await _subCategoryRepository.InsertAndGetIdAsync(new SubCategory { Name = input.Name, CategoryId = (int)input.CategoryId });
                await SetSubItems(new SubItemsDto(newSubCategoryId, ReferenceEnum.SubCategory, input.List));

                break;

            case ReferenceEnum.SubCategoryType:
                var newTypeId = await _typeRepository.InsertAndGetIdAsync(new SubCategoryType { Name = input.Name });
                await SetSubItems(new SubItemsDto(newTypeId, ReferenceEnum.SubCategoryType, input.List));

                break;

            default:
                throw new UserFriendlyException("Указан не правильный тип!");
            }
        }
        public async Task Update(ReferenceDto input)
        {
            switch (input.Type)
            {
            case ReferenceEnum.Category:
                var category = await _categoryRepository.GetAsync(input.Id);

                category.Name = input.Name;
                break;

            case ReferenceEnum.SubCategory:
                var subCategory = await _subCategoryRepository.GetAsync(input.Id);

                subCategory.Name       = input.Name;
                subCategory.CategoryId = (int)input.CategoryId;
                subCategory.SubCategoryToTypes.Clear();
                await SetSubItems(new SubItemsDto(input.Id, ReferenceEnum.SubCategory, input.List));

                break;

            case ReferenceEnum.SubCategoryType:
                var categoryType = await _typeRepository.GetAsync(input.Id);

                categoryType.Name = input.Name;
                categoryType.SubCategoryToTypes.Clear();
                await SetSubItems(new SubItemsDto(input.Id, ReferenceEnum.SubCategoryType, input.List));

                break;

            default:
                throw new UserFriendlyException("Указан не правильный тип!");
            }
        }
        public ActionResult Create(int folderId, FormCollection formData)
        {
            ReferenceCreateViewModel model = GetCreateViewModel(folderId);

            UpdateModel(model.Instance, formData);
            if (ModelState.IsValid)
            {
                model.Instance.FolderId = folderId;
                int selectedTemplateId;
                if (int.TryParse(formData["SelectedTemplateId"], out selectedTemplateId))
                {
                    model.Instance.TemplateId = selectedTemplateId;
                    // Save data
                    IFacadeUpdateResult <ReferenceData> result = Service.SaveReference(model.Instance);
                    if (result.IsSuccessful)
                    {
                        ReferenceDto savedRef = result.ToDto(new ReferenceConverter());
                        return(RedirectToAction(DetailAction, new { id = savedRef.Id }));
                    }
                    else
                    {
                        ProcUpdateResult(result.ValidationResult, result.Exception);
                    }
                }
                else
                {
                    ModelState.AddModelError("InputError", "Please select Template.");
                }
            }

            return(View(model));
        }
Exemple #4
0
 public ReferenceCreateViewModel()
 {
     Instance             = new ReferenceDto();
     Instance.EnableAds   = true;
     Instance.EnableTopAd = true;
     IsEditing            = true;
 }
        // POST: api/Reference
        public ReferenceDto Post([FromBody] ReferenceDto value)
        {
            var reference = value.Entity();

            repository.Save(reference);
            return((ReferenceDto)reference);
        }
        // PUT: api/Reference/5
        public ReferenceDto Put(int id, [FromBody] ReferenceDto value)
        {
            var reference = repository.Get <Reference>(id);

            value.Merge(reference);
            repository.Save(reference);
            return((ReferenceDto)reference);
        }
Exemple #7
0
        public async Task <IActionResult> Post([FromBody] ReferenceDto referenceDto, CancellationToken cancellationToken)
        {
            var reference = this.mapper.Map <ReferenceDto, Reference>(referenceDto);

            await this.referenceService.AddAsync(reference, cancellationToken);

            return(NoContent());
        }
 public void AddReference(ReferenceDto reference)
 {
     try
     {
         DeclarationDal.AddReference(reference);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #9
0
        public IFacadeUpdateResult <ReferenceData> SaveReference(ReferenceDto reference)
        {
            ReferenceData data = ReferenceConverter.ConvertToData(reference);

            using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CMSDataStoreKey))
            {
                ReferenceFacade facade = new ReferenceFacade(uow);
                IFacadeUpdateResult <ReferenceData> result = facade.SaveReference(data);
                return(result);
            }
        }
        public async Task <IActionResult> Post([FromBody] ReferenceDto referenceDto, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var reference = this.mapper.Map <ReferenceDto, Reference>(referenceDto);

            await this.referenceService.AddAsync(reference, cancellationToken);

            return(NoContent());
        }
Exemple #11
0
        public void ValidInput_ShouldReturnValidResult()
        {
            // Arrange
            var localizer = ServiceProvider.GetRequiredService <IStringLocalizer <ReferenceValidator> >();
            var validator = ServiceProvider.GetRequiredService <ReferenceValidator>();

            var validInput = new ReferenceDto {
                ReferenceId = Guid.NewGuid()
            };

            // Act
            var validationResult = validator.Validate(validInput);

            // Assert
            validationResult.IsValid.Should().BeTrue();
        }
Exemple #12
0
 public void AddReference(ReferenceDto reference)
 {
     try
     {
         using (var context = new CTDSContext())
         {
             var data = Mapper.DtoToReferenceModel(reference);
             context.Reference.AddOrUpdate(d => d.ReferenceId, data);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #13
0
        public OperationResponse <bool> Post(EditDeclaration editDeclaration)
        {
            OperationResponse <bool> response = new OperationResponse <bool>();

            try
            {
                var newDeclaration          = editDeclaration.Declaration;
                DeclarationValidator obj    = new DeclarationValidator();
                ValidationResult     result = obj.Validate(newDeclaration);
                if (result.IsValid)
                {
                    var data = DeclarationBll.EditDeclaration(newDeclaration);

                    ReferenceDto reference = new ReferenceDto();
                    for (int i = 0; i < editDeclaration.ReferenceData.Length; i++)
                    {
                        reference.DeclarationId = newDeclaration.DeclarationId;
                        reference.ReferenceId   = editDeclaration.ReferenceData[i].ReferenceId;
                        reference.InvoiceDate   = editDeclaration.ReferenceData[i].InvoiceDate;
                        reference.Reference     = editDeclaration.ReferenceData[i].Reference;
                        reference.Type          = editDeclaration.ReferenceData[i].Type;
                        DeclarationBll.AddReference(reference);
                    }
                    response.OnSuccess(data, "Record Successfully Updated");
                    return(response);
                }
                else
                {
                    List <string> errors = new List <string>();
                    foreach (var err in result.Errors)
                    {
                        errors.Add(err.ErrorMessage);
                    }
                    response.OnError("one or more validations failed", errors);
                    return(response);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.StackTrace);
                response.OnException("Error in updating record");
                return(response);
            }
        }
Exemple #14
0
        public OperationResponse <bool> Post(AddDeclaration newDeclaration)
        {
            OperationResponse <bool> response = new OperationResponse <bool>();

            try
            {
                var declaration             = newDeclaration.Declaration;
                DeclarationValidator obj    = new DeclarationValidator();
                ValidationResult     result = obj.Validate(declaration);
                if (result.IsValid)
                {
                    var          data      = DeclarationBll.AddDeclaration(declaration);
                    var          id        = data;
                    ReferenceDto reference = new ReferenceDto();
                    for (int i = 0; i < newDeclaration.ReferenceData.Length; i++)
                    {
                        reference.DeclarationId = data;
                        reference.InvoiceDate   = newDeclaration.ReferenceData[i].InvoiceDate;
                        reference.Reference     = newDeclaration.ReferenceData[i].Reference;
                        reference.Type          = newDeclaration.ReferenceData[i].Type;
                        DeclarationBll.AddReference(reference);
                    }
                    response.OnSuccess(true, "Declaration Successfully added!");
                    return(response);
                }
                else
                {
                    List <string> error = new List <string>();
                    foreach (var err in result.Errors)
                    {
                        error.Add(err.ErrorMessage);
                    }
                    response.OnError("One or more validations failed", error);
                    return(response);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.StackTrace);
                response.OnException("Request to Add new declaration failed at server side.");
                return(response);
            }
        }
Exemple #15
0
        public void EmptyReferenceId_ShouldReturnInvalidResult()
        {
            // Arrange
            var localizer = ServiceProvider.GetRequiredService <IStringLocalizer <ReferenceValidator> >();
            var validator = ServiceProvider.GetRequiredService <ReferenceValidator>();

            var invalidInput = new ReferenceDto {
                ReferenceId = Guid.Empty
            };

            // Act
            var validationResult = validator.Validate(invalidInput);

            // Assert
            AssertInvalidResult(
                validationResult: validationResult,
                propertyName: nameof(IReference.ReferenceId),
                message: localizer[ReferenceValidator.EmptyReferenceIdMessageName]
                );
        }
Exemple #16
0
 public ReferenceTable DtoToReferenceModel(ReferenceDto reference)
 {
     return(Mapper.Map <ReferenceTable>(reference));
 }