Example #1
0
        public Framework.Entities.GenericExecResult <ComCountDto> Add(Guid targetId, string categoryId = null, int count = 1, string table = null)
        {
            table = string.IsNullOrEmpty(table) ? TableName : table;
            var entity = this.IBaseDao.FirstOrDefault <Com_Count>(
                Where.Create()
                .Eq("TargetId", targetId)
                .Eq("CategoryId", categoryId)
                .EqIfNotNull("TableName", table)
                );

            if (entity == null)
            {
                entity = new Com_Count()
                {
                    Id              = Guid.NewGuid(),
                    Count           = 0,
                    TargetId        = targetId,
                    CreatedDatetime = DateTime.Now,
                    TableName       = table,
                    CategoryId      = categoryId
                };
                this.IBaseDao.Insert(entity);
            }
            entity.Count += count;
            var updateEntity = this.IBaseDao.Update(entity);
            var dto          = MapToDto(updateEntity);

            return(new Framework.Entities.GenericExecResult <ComCountDto>()
            {
                Data = dto,
                Success = true
            });
        }
Example #2
0
        public GenericExecResult <ComCountDto> FindFirstOrDefaultByTargetIdAndCategoryId(Guid targetId, string categoryId, string table = null)
        {
            table = string.IsNullOrEmpty(table) ? TableName : table;
            Com_Count entity = this.IBaseDao.FirstOrDefault <Com_Count>(
                Where.Create()
                .Eq("TargetId", targetId)
                .Eq("CategoryId", categoryId)
                .EqIfNotNull("TableName", table)
                );
            var dtoList = MapToDto(entity);

            return(new Framework.Entities.GenericExecResult <ComCountDto>()
            {
                Data = dtoList,
                Success = true
            });
        }