/// <inheritdoc />
 /// <summary>
 /// Get notification by id
 /// </summary>
 /// <param name="notificationId"></param>
 /// <returns></returns>
 public virtual async Task <ResultModel <Dictionary <string, object> > > GetNotificationByIdAsync(Guid?notificationId)
 {
     if (notificationId == null)
     {
         return(new NotFoundResultModel <Dictionary <string, object> >());
     }
     return(await _dataService.GetById <SystemNotifications>(notificationId.Value));
 }
Пример #2
0
        public virtual async Task <JsonResult> SaveTableCellData(Guid?entityId, Guid?propertyId, Guid?rowId, string value)
        {
            var result = new ResultModel();

            if (entityId == null || propertyId == null || rowId == null)
            {
                result.Errors.Add(new ErrorModel(string.Empty, "Not specified data"));
                return(Json(result));
            }

            var entity = await _pagesContext.Table.Include(x => x.TableFields).FirstOrDefaultAsync(x => x.Id == entityId);

            if (entity == null)
            {
                result.Errors.Add(new ErrorModel(string.Empty, "Entity not found"));
                return(Json(result));
            }

            if (entity.IsSystem || entity.IsPartOfDbContext)
            {
                result.Errors.Add(new ErrorModel(string.Empty, "The system entity can not be edited"));
                return(Json(result));
            }

            var property = entity.TableFields.First(x => x.Id == propertyId);

            if (property == null)
            {
                result.Errors.Add(new ErrorModel(string.Empty, "Not found entity column"));
                return(Json(result));
            }

            var row = await _service.GetById(entity.Name, rowId.Value);

            if (!row.IsSuccess)
            {
                result.Errors.Add(new ErrorModel(string.Empty, "Entry Not found"));
                return(Json(result));
            }

            if (row.Result.ContainsKey(property.Name))
            {
                switch (property.DataType)
                {
                case TableFieldDataType.Guid:
                {
                    Guid.TryParse(value, out var parsed);
                    row.Result[property.Name] = parsed;
                }
                break;

                case TableFieldDataType.Boolean:
                {
                    bool.TryParse(value, out var val);
                    row.Result[property.Name] = val;
                }
                break;

                case TableFieldDataType.Int:
                {
                    try
                    {
                        row.Result[property.Name] = Convert.ToInt32(value);
                    }
                    catch
                    {
                        row.Result[property.Name] = value;
                    }
                }
                break;

                case TableFieldDataType.Decimal:
                {
                    try
                    {
                        row.Result[property.Name] = Convert.ToDecimal(value);
                    }
                    catch
                    {
                        row.Result[property.Name] = value;
                    }
                }
                break;

                case TableFieldDataType.Date:
                case TableFieldDataType.DateTime:
                {
                    DateTime.TryParseExact(value, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None,
                                           out var parsed);
                    row.Result[property.Name] = parsed;
                }
                break;

                default:
                    row.Result[property.Name] = value;
                    break;
                }
            }

            if (row.Result.ContainsKey(nameof(BaseModel.Changed)))
            {
                row.Result[nameof(BaseModel.Changed)] = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            }

            var req = await _service.Update(entity.Name, row.Result);

            if (!req.IsSuccess)
            {
                result.Errors.Add(new ErrorModel(string.Empty, "Fail to save data"));
                return(Json(result));
            }

            result.IsSuccess = true;
            return(Json(result));
        }