public Store Create(DO.Store store, Guid?clientId = null, bool storeExists = false, bool onlyApplicationMain = false, bool userExists = false, bool syncInApplication = false) { Store newStore = new Store(); if (storeExists) { var _store = storeService.Get(store.Code); if (!_store.IsNull() && !_store.Code.IsEmpty()) { throw new ArgumentException("Esta loja já possui cadastro com o nome '{0}' e código {1}".ToFormat(_store.Name, _store.Code)); } } if (onlyApplicationMain) { if (!clientId.HasValue) { throw new ArgumentException("Não é possível efetuar essa operação"); } var applicationStore = applicationStoreRepository.GetByClientId(clientId.Value); if (!applicationStore.Store.IsMain) { throw new ArgumentException("Não é possível efetuar essa operação"); } } using (var transaction = Connection.BeginTransaction()) { try { newStore = storeService.CreateStore(store); applicationStoreService.CreateAppStore(newStore); roleService.SaveAll(newStore.Code); } catch { transaction.Rollback(); throw; } } return(newStore); }
public Store(DO.Store store, bool withMetadataFields = false) { this.Code = store.Code; this.Name = store.Name; this.Cnpj = store.Cnpj; this.IsMain = store.IsMain; this.Logo = store.GetLogoURL(); if (!store.Metadata.IsNull()) { var metadata = new Dictionary <string, object>(); store.Metadata.ForEach(m => metadata.Add(m.Field.JsonId, m.Value)); this.Metadata = metadata; if (withMetadataFields) { MetadataFields = store.Metadata.OrderBy(m => m.Field.SaveDate).Select(m => new DTO.MetadataField(m.Field, m)).ToList(); } } }