示例#1
0
        public IActionResult Post([Required][Image] IFormFile file)
        {
            var metadata = new FileMetadata
            {
                OriginalFileName = file.FileName,
                UploadDate       = DateTime.Now,
                FileType         = FileType.Image,
                OwnerId          = User.GetId()
            };

            var fileObj = new FileModel
            {
                Metadata = metadata,
                Data     = GetPreprocessedImage(file)
            };

            try
            {
                _db.StartTransaction();
                _db.FileMetadata.Create(metadata);
                _fs.Create(fileObj);
                _db.Commit();
            }
            catch
            {
                _db.Rollback();
                _fs.Delete(metadata);
                throw;
            }

            return(StatusCode((int)HttpStatusCode.Created, fileObj.Metadata.Id));
        }
示例#2
0
        public IActionResult Post(AdvertDTO advert)
        {
            FileMetadata image = null;

            if (advert.ImageId != null)
            {
                image = _db.FileMetadata.Read(advert.ImageId.Value);
                if (image == null)
                {
                    return(NotFound($"Image {image.Id} not found!"));
                }
                else if (image.Assigned)
                {
                    return(Conflict($"Image {image.Id} is already used!"));
                }
                else if (image.OwnerId != User.GetId())
                {
                    return(Conflict($"Image {image.Id} is owned by another user!"));
                }
            }

            advert.UserId = User.GetId();
            var advertEntity = _mapper.Map <Advert>(advert);

            try
            {
                _db.StartTransaction();
                var advertId = _db.Adverts.Create(advertEntity);
                _db.Adverts.CreateFavorite(new AdvertFavorite
                {
                    UserId   = User.GetId(),
                    AdvertId = advertId
                });

                if (image != null)
                {
                    image.Assigned = true;
                    _db.FileMetadata.Update(image);
                }

                _db.Commit();
            }
            catch
            {
                _db.Rollback();
                throw;
            }

            return(Created(string.Empty, advertEntity.Id));
        }
示例#3
0
        private static User CreateAndCommitUserWithGroup(IUserRepository repository, IUserGroupRepository userGroupRepository, IDatabaseUnitOfWork unitOfWork)
        {
            var user = MockedUser.CreateUser();

            repository.AddOrUpdate(user);
            unitOfWork.Commit();

            var group = MockedUserGroup.CreateUserGroup();

            userGroupRepository.AddOrUpdateGroupWithUsers(@group, new[] { user.Id });
            unitOfWork.Commit();

            return(user);
        }
示例#4
0
        public KSociety.Com.App.Dto.Res.ModifyField.Common.Connection Execute(Connection request)
        {
            var commonConnection = _connectionRepository.Find(request.Id); //.GetAllConnection().SingleOrDefault(g => g.Id == request.Id);

            commonConnection?.ModifyField(request.FieldName, request.Value);
            return(new KSociety.Com.App.Dto.Res.ModifyField.Common.Connection(_unitOfWork.Commit() > 0));
        }
示例#5
0
        public int Create(ContractDTO model, Role initiatorRole)
        {
            if (!ValidateContractForCreate(model, initiatorRole, out string error))
            {
                throw new EBValidationException(error);
            }

            try
            {
                db.StartTransaction();

                int createdId  = db.Contracts.Create(_mapper.Map <Contract>(model));
                var fullEntity = db.Contracts.Read(createdId);

                var report = GeneratePdfReport(_mapper.Map <ContractDTO>(fullEntity));
                fileRepository.Create(report);

                fullEntity.ReportId = report.Metadata.Id;
                db.Contracts.Update(fullEntity);

                db.Commit();
                return(createdId);
            }
            catch
            {
                db.Rollback();
                throw;
            }
        }
示例#6
0
        public KSociety.Com.App.Dto.Res.ModifyField.Common.Tag Execute(Tag request)
        {
            var commonTag = _tagRepository.Find(request.Id); //GetAllTag().SingleOrDefault(tag => tag.Id == request.Id);

            commonTag?.ModifyField(request.FieldName, request.Value);
            return(new KSociety.Com.App.Dto.Res.ModifyField.Common.Tag(_unitOfWork.Commit() > 0));
        }
        public KSociety.Com.App.Dto.Res.Add.Logix.LogixTag Execute(LogixTag request)
        {
            var logixTag = _mapper.Map <Domain.Entity.Logix.LogixTag>(request);

            _tagRepository.Add(logixTag);
            return(_unitOfWork.Commit() == -1 ? new KSociety.Com.App.Dto.Res.Add.Logix.LogixTag(Guid.Empty) : new KSociety.Com.App.Dto.Res.Add.Logix.LogixTag(logixTag.Id));
        }
        public KSociety.Com.App.Dto.Res.Copy.Common.TagGroup Execute(TagGroup request)
        {
            var commonTagGroup = _mapper.Map <Domain.Entity.Common.TagGroup>(request);

            _tagGroupRepository.Add(commonTagGroup);
            return(_unitOfWork.Commit() == -1 ? new KSociety.Com.App.Dto.Res.Copy.Common.TagGroup(Guid.Empty) : new KSociety.Com.App.Dto.Res.Copy.Common.TagGroup(commonTagGroup.Id));
        }
        public KSociety.Com.App.Dto.Res.Add.S7.S7Connection Execute(S7Connection request)
        {
            var s7Connection = _mapper.Map <Domain.Entity.S7.S7Connection>(request);

            _connectionRepository.Add(s7Connection);
            return(_unitOfWork.Commit() == -1 ? new KSociety.Com.App.Dto.Res.Add.S7.S7Connection(Guid.Empty) : new KSociety.Com.App.Dto.Res.Add.S7.S7Connection(s7Connection.Id));
        }
示例#10
0
        public KSociety.Com.App.Dto.Res.Import.Logix.LogixTag Execute(LogixTag request)
        {
            var result = _tagRepository.ImportCsv(request.ByteArray);
            var output = _unitOfWork.Commit();

            return(output == -1 ? new KSociety.Com.App.Dto.Res.Import.Logix.LogixTag(result)
                : new KSociety.Com.App.Dto.Res.Import.Logix.LogixTag(false));
        }
示例#11
0
        public KSociety.Com.App.Dto.Res.Remove.Common.Tag Execute(Tag request)
        {
            var commonTag = _tagRepository.Find(request.Id); //.GetAllTag().SingleOrDefault(tag => tag.Id == request.Id);

            _tagRepository.Delete(commonTag);

            return(new KSociety.Com.App.Dto.Res.Remove.Common.Tag(_unitOfWork.Commit() > 0));
        }
示例#12
0
        public KSociety.Com.App.Dto.Res.Remove.Logix.LogixTag Execute(LogixTag request)
        {
            var logixTag = _tagRepository.Find(request.Id); //.GetAllLogixTag().SingleOrDefault(g => g.Id == request.Id);

            _tagRepository.Delete(logixTag);

            return(new KSociety.Com.App.Dto.Res.Remove.Logix.LogixTag(_unitOfWork.Commit() > 0));
        }
示例#13
0
        public KSociety.Com.App.Dto.Res.Update.Common.Connection Execute(Connection request)
        {
            var commonConnection = _mapper.Map <Domain.Entity.Common.Connection>(request);
            var entryEntity      = _connectionRepository.Update(commonConnection);
            var result           = _unitOfWork.Commit();

            return(result == -1 ? new KSociety.Com.App.Dto.Res.Update.Common.Connection(Guid.Empty) : new KSociety.Com.App.Dto.Res.Update.Common.Connection(commonConnection.Id));
        }
        public KSociety.Com.App.Dto.Res.Remove.Common.Connection Execute(Connection request)
        {
            var commonConnection = _connectionRepository.Find(request.Id); //.GetAllConnection().SingleOrDefault(g => g.Id == request.Id);

            _connectionRepository.Delete(commonConnection);

            return(new KSociety.Com.App.Dto.Res.Remove.Common.Connection(_unitOfWork.Commit() > 0));
        }
        public KSociety.Com.App.Dto.Res.Import.S7.S7Connection Execute(S7Connection request)
        {
            var result = _connectionRepository.ImportCsv(request.ByteArray);
            var output = _unitOfWork.Commit();

            return(output == -1 ? new KSociety.Com.App.Dto.Res.Import.S7.S7Connection(result)
                : new KSociety.Com.App.Dto.Res.Import.S7.S7Connection(false));
        }
示例#16
0
        public KSociety.Com.App.Dto.Res.Import.Common.TagGroup Execute(TagGroup request)
        {
            var result = _tagGroupRepository.ImportCsv(request.ByteArray);
            var output = _unitOfWork.Commit();

            return(output == -1 ? new KSociety.Com.App.Dto.Res.Import.Common.TagGroup(result)
                : new KSociety.Com.App.Dto.Res.Import.Common.TagGroup(false));
        }
示例#17
0
        public KSociety.Com.App.Dto.Res.Update.Common.Tag Execute(Tag request)
        {
            var commonTag = _mapper.Map <Domain.Entity.Common.Tag>(request);

            _tagRepository.Update(commonTag);
            var result = _unitOfWork.Commit();

            return(result == -1 ? new KSociety.Com.App.Dto.Res.Update.Common.Tag(Guid.Empty) : new KSociety.Com.App.Dto.Res.Update.Common.Tag(commonTag.Id));
        }
示例#18
0
        public KSociety.Com.App.Dto.Res.Add.S7.S7Tag Execute(S7Tag request)
        {
            var s7Tag = _mapper.Map <Domain.Entity.S7.S7Tag>(request);

            _tagRepository.Add(s7Tag);
            var result = _unitOfWork.Commit();

            return(result == -1 ? new KSociety.Com.App.Dto.Res.Add.S7.S7Tag(Guid.Empty) : new KSociety.Com.App.Dto.Res.Add.S7.S7Tag(s7Tag.Id));
        }
示例#19
0
        public KSociety.Com.App.Dto.Res.ModifyField.Logix.LogixTag Execute(LogixTag request)
        {
            var logixTag = _tagRepository.Find(request.Id); //.GetAllLogixTag().SingleOrDefault(g => g.Id == request.Id);

            logixTag?.ModifyField(request.FieldName, request.Value);
            var result = _unitOfWork.Commit();

            return(new KSociety.Com.App.Dto.Res.ModifyField.Logix.LogixTag(result > 0));
        }
        public KSociety.Com.App.Dto.Res.Update.Logix.LogixConnection Execute(LogixConnection request)
        {
            var logixConnection = _mapper.Map <Domain.Entity.Logix.LogixConnection>(request);

            _connectionRepository.Update(logixConnection);


            return(_unitOfWork.Commit() == -1 ? new KSociety.Com.App.Dto.Res.Update.Logix.LogixConnection(Guid.Empty) : new KSociety.Com.App.Dto.Res.Update.Logix.LogixConnection(logixConnection.Id));
        }
示例#21
0
        public KSociety.Com.App.Dto.Res.ModifyField.S7.S7Connection Execute(S7Connection request)
        {
            var s7Connection = _connectionRepository.Find(request.Id); //.GetAllS7Connection().SingleOrDefault(g => g.Id == request.Id);

            s7Connection?.ModifyField(request.FieldName, request.Value);

            var result = _unitOfWork.Commit();

            return(new KSociety.Com.App.Dto.Res.ModifyField.S7.S7Connection(result > 0));
        }
示例#22
0
        public KSociety.Com.App.Dto.Res.ModifyField.Common.TagGroup Execute(TagGroup request)
        {
            var commonTagGroup = _tagGroupRepository.Find(request.Id); //.GetAllTagGroup().SingleOrDefault(tagGroup => tagGroup.Id == request.Id);

            commonTagGroup?.ModifyField(request.FieldName, request.Value);

            var result = _unitOfWork.Commit();

            return(new KSociety.Com.App.Dto.Res.ModifyField.Common.TagGroup(result > 0));
        }
示例#23
0
        public KSociety.Com.App.Dto.Res.ModifyField.S7.S7Tag Execute(S7Tag request)
        {
            _logger.LogInformation("" + request.Id + " " + request.FieldName + " " + request.Value);
            var s7Tag = _tagRepository.Find(request.Id); //.GetAllS7Tag().SingleOrDefault(g => g.Id == request.Id);

            s7Tag.AddLoggerFactory(_loggerFactory);
            s7Tag?.ModifyField(request.FieldName, request.Value);
            var result = new KSociety.Com.App.Dto.Res.ModifyField.S7.S7Tag(_unitOfWork.Commit() > 0);

            return(result);
        }
示例#24
0
        public ChatDTO CreateChat(ChatDTO chat)
        {
            try
            {
                _db.StartTransaction();
                var chatEntity = _mapper.Map <Chat>(chat);
                foreach (var u in chatEntity.Participants)
                {
                    u.AddedDate = DateTime.Now;
                }
                var chatId = _db.Chats.Create(chatEntity);
                _db.Commit();

                var created = GetChat(chatId);
                return(created);
            }
            catch
            {
                _db.Rollback();
                throw;
            }
        }
示例#25
0
        public KSociety.Com.App.Dto.Res.Remove.S7.S7Tag Execute(S7Tag request)
        {
            try
            {
                //foreach (var VARIABLE in _tagRepository.GetAllS7Tag().Where(g => g.Id == request.Id))
                //{
                //    _logger.LogInformation(VARIABLE.Name + " " + VARIABLE.Id + " " + request.Id);
                //}
                var s7Tag = _tagRepository.Find(request.Id); //.GetAllS7Tag().SingleOrDefault(g => g.Id == request.Id);

                _tagRepository.Delete(s7Tag);
                var result = new KSociety.Com.App.Dto.Res.Remove.S7.S7Tag(_unitOfWork.Commit() > 0);
                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError("" + ex.Message + " - " + ex.StackTrace);
                return(new KSociety.Com.App.Dto.Res.Remove.S7.S7Tag(false));
            }
        }
        private IEnumerable <ITemplate> CreateHierarchy(ITemplateRepository repository, IDatabaseUnitOfWork unitOfWork)
        {
            var parent = new Template("parent", "parent")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };

            var child1 = new Template("child1", "child1")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };
            var toddler1 = new Template("toddler1", "toddler1")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };
            var toddler2 = new Template("toddler2", "toddler2")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };
            var baby1 = new Template("baby1", "baby1")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };

            var child2 = new Template("child2", "child2")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };
            var toddler3 = new Template("toddler3", "toddler3")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };
            var toddler4 = new Template("toddler4", "toddler4")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };
            var baby2 = new Template("baby2", "baby2")
            {
                Content = @"<%@ Master Language=""C#"" %>"
            };


            child1.MasterTemplateAlias = parent.Alias;
            child1.MasterTemplateId    = new Lazy <int>(() => parent.Id);
            child2.MasterTemplateAlias = parent.Alias;
            child2.MasterTemplateId    = new Lazy <int>(() => parent.Id);

            toddler1.MasterTemplateAlias = child1.Alias;
            toddler1.MasterTemplateId    = new Lazy <int>(() => child1.Id);
            toddler2.MasterTemplateAlias = child1.Alias;
            toddler2.MasterTemplateId    = new Lazy <int>(() => child1.Id);

            toddler3.MasterTemplateAlias = child2.Alias;
            toddler3.MasterTemplateId    = new Lazy <int>(() => child2.Id);
            toddler4.MasterTemplateAlias = child2.Alias;
            toddler4.MasterTemplateId    = new Lazy <int>(() => child2.Id);

            baby1.MasterTemplateAlias = toddler2.Alias;
            baby1.MasterTemplateId    = new Lazy <int>(() => toddler2.Id);

            baby2.MasterTemplateAlias = toddler4.Alias;
            baby2.MasterTemplateId    = new Lazy <int>(() => toddler4.Id);

            repository.AddOrUpdate(parent);
            repository.AddOrUpdate(child1);
            repository.AddOrUpdate(child2);
            repository.AddOrUpdate(toddler1);
            repository.AddOrUpdate(toddler2);
            repository.AddOrUpdate(toddler3);
            repository.AddOrUpdate(toddler4);
            repository.AddOrUpdate(baby1);
            repository.AddOrUpdate(baby2);
            unitOfWork.Commit();

            return(new[] { parent, child1, child2, toddler1, toddler2, toddler3, toddler4, baby1, baby2 });
        }