Exemplo n.º 1
0
        public async Task <OperationResult> UpdateFields(FieldsUpdateModel fieldsModel)
        {
            try
            {
                List <int>           list   = fieldsModel.Fields.Select(s => s.Id).ToList(); // list of field ids.
                List <CustomerField> fields = await _dbContext.CustomerFields
                                              .Where(x => list.Contains(x.FieldId))
                                              .ToListAsync().ConfigureAwait(false); // lists the fields for the specific customer.

                if (fields.Any())
                {
                    UpdateFields(_dbContext, fieldsModel, fields);
                }

                return(new OperationResult(true,
                                           _localizationService.GetString("FieldsUpdatedSuccessfully")));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationResult(false,
                                           _localizationService.GetString("ErrorWhileUpdatingFields")));
            }
        }
Exemplo n.º 2
0
        public async Task <OperationDataResult <FieldsUpdateModel> > GetFields()
        {
            try
            {
                List <FieldUpdateModel> fields = await _dbContext.CustomerFields
                                                 .Include("Field").OrderBy(x => x.DisplayIndex)
                                                 .Select(x => new FieldUpdateModel()
                {
                    FieldStatus = x.FieldStatus,
                    Id          = x.FieldId,
                    Name        = x.Field.Name,
                }).ToListAsync().ConfigureAwait(false);

                // Mode Id field to top
                //fields.Reverse();
                // int index = fields.FindIndex(x => x.Name == "Id");
                // FieldUpdateModel item = fields[index];
                // fields[index] = fields[0];
                // fields[0] = item;
                FieldsUpdateModel result = new FieldsUpdateModel()
                {
                    Fields = fields,
                };
                return(new OperationDataResult <FieldsUpdateModel>(true, result));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <FieldsUpdateModel>(false,
                                                                   _localizationService.GetString("ErrorWhileObtainingFieldsInfo")));
            }
        }
Exemplo n.º 3
0
        private void UpdateFields(CustomersPnDbAnySql dbContext, FieldsUpdateModel fieldsUpdate, List <CustomerField> customerFields)
        {
            foreach (CustomerField field in customerFields)                                                   // Itterating through a list of customerFields.
            {
                FieldUpdateModel fieldModel = fieldsUpdate.Fields.FirstOrDefault(x => x.Id == field.FieldId); // takes field from list of fields
                if (fieldModel != null)
                {
                    field.FieldStatus = fieldModel.FieldStatus;// sets new status for field, based on the updatemodels status.
                }
            }

            dbContext.SaveChanges();
        }
Exemplo n.º 4
0
        public void FieldUpdateModel_Update_DoesUpdate()
        {
            // Arrange
            Random rnd      = new Random();
            Field  newField = new Field
            {
                Name = Guid.NewGuid().ToString()
            };

            newField.Create(DbContext);

            // Act
            FieldUpdateModel fieldUpdateModel = new FieldUpdateModel();

            fieldUpdateModel.Name = newField.Name;

            List <FieldUpdateModel> list = new List <FieldUpdateModel>();

            list.Add(fieldUpdateModel);

            FieldsUpdateModel fieldsUpdate = new FieldsUpdateModel();

            fieldsUpdate.Fields = list;
            // TODO: FIX
            newField.Update(DbContext);

            Field        dbField   = DbContext.Fields.AsNoTracking().First();
            List <Field> fieldList = DbContext.Fields.AsNoTracking().ToList();

            // Assert
            Assert.NotNull(dbField);

            Assert.AreEqual(1, fieldList.Count());

            Assert.AreEqual(fieldUpdateModel.Name, dbField.Name);
        }
Exemplo n.º 5
0
 public async Task <OperationResult> UpdateFields([FromBody] FieldsUpdateModel fieldsModel)
 {
     return(await _fieldsService.UpdateFields(fieldsModel));
 }