Exemple #1
0
        public static IList <CoursePreview> GetList()
        {
            var repo = UowFactory.Get().Repository <CourseRepository>();

            return(ModelHelper.FetchList <CoursePreview, Course>(repo.GetAll()));
            //return ModelHelper.FetchList<CoursePreview, CourseDto>(await repo.GetAllAsync());
        }
        protected override void OnHandle(UpdatePortalCommand command)
        {
            var settings = ConvertTo(command.SettingsDto);

            using (var uow = UowFactory.Create())
            {
                var portal = uow.Context
                             .Query <Entities.Sites.Portal>()
                             .SingleOrDefault();
                if (portal == null)
                {
                    throw new EntityNotFoundException("Portal entity not found");
                }
                portal.Name        = command.Name;
                portal.Title       = command.Title;
                portal.Description = command.Description;
                uow.Context.Update(portal);

                if (settings != null)
                {
                    _settingsProvider.SaveSettings(uow, settings);
                }

                uow.Complete();
            }
        }
Exemple #3
0
        public void EditarTitulosConsignacionDetalle(IList <TituloConsignacionRendidasDetalleDto> titulosConsignacionRendidaDetalle)
        {
            if (!titulosConsignacionRendidaDetalle.Any())
            {
                return;
            }

            using (var uow = UowFactory.Create <ILaPazUow>())
            {
                var tituloConsignacionRendidaId = titulosConsignacionRendidaDetalle.First().TituloConsignacionRendidaId;

                decimal nuevoImporte = 0;

                foreach (var tituloConsignacionRendidaDetalle in titulosConsignacionRendidaDetalle)
                {
                    var tituloConsignacionRendidaActual = uow.TitulosConsignacionesRendidasDetalle.Obtener(x => x.Id == tituloConsignacionRendidaDetalle.Id);
                    tituloConsignacionRendidaActual.PrecioCompra = tituloConsignacionRendidaDetalle.PrecioCompra;
                    tituloConsignacionRendidaActual.Importe      = tituloConsignacionRendidaDetalle.Importe;
                    uow.TitulosConsignacionesRendidasDetalle.Modificar(tituloConsignacionRendidaActual);

                    nuevoImporte += tituloConsignacionRendidaDetalle.PrecioCompra * tituloConsignacionRendidaDetalle.Cantidad;
                }

                var tituloConsignacionRendida =
                    uow.TitulosConsignacionesRendidas.Obtener(x => x.Id == tituloConsignacionRendidaId);

                tituloConsignacionRendida.Importe = nuevoImporte;

                uow.TitulosConsignacionesRendidas.Modificar(tituloConsignacionRendida);

                uow.Commit();
            }
        }
Exemple #4
0
        protected override void OnHandle(AddJobCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                Validate(uow, command);

                var jobType = (JobType)Enum.Parse(typeof(JobType), command.Type);

                var ownerId = command.OwnerUserId;
                var siteId  = command.SiteId;
                var owner   = uow.Context.Query <Entities.Security.User>().SingleOrDefault(u => u.Id == ownerId);
                var site    = uow.Context.Query <Entities.Sites.Site>().SingleOrDefault(s => s.Id == siteId);

                var newJob = new Entities.Jobs.Job
                {
                    Name        = command.Name,
                    Type        = jobType,
                    IsSystemJob = command.IsSystemJob,
                    Description = command.Description,
                    Created     = command.Created,
                    Owner       = owner,
                    Site        = site,
                };
                uow.Context.Add(newJob);

                uow.Complete();
            }
        }
Exemple #5
0
        private void FrmReporteConsignaciones_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            reportViewer1.LocalReport.DataSources.Clear();
            reportViewer1.ProcessingMode = ProcessingMode.Local;
            string appPath    = Application.StartupPath.Replace("\\bin\\Debug", "");
            string reportPath = @"\RDLS\RendicionConsignaciones.rdl";

            reportViewer1.LocalReport.ReportPath = appPath + reportPath;
            reportViewer1.ZoomPercent            = 130;

            using (var uow = UowFactory.Create <ILaPazUow>())
            {
                var proveedor = uow.Proveedores.Obtener(p => p.Id == ProveedorId);

                reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ReporteDataset", Listado));

                var fecha = DateTime.Now.ToShortDateString();
                var hora  = DateTime.Now.ToShortTimeString();


                var parametros = new List <ReportParameter>
                {
                    new ReportParameter("Fecha", fecha),
                    new ReportParameter("Hora", hora),
                    new ReportParameter("Desde", Desde.ToShortDateString()),
                    new ReportParameter("Hasta", Hasta.ToShortDateString()),
                    new ReportParameter("ProveedorNombre", proveedor.Denominacion)
                };

                reportViewer1.LocalReport.SetParameters(parametros);
                this.reportViewer1.RefreshReport();
                this.Cursor = Cursors.Default;
            }
        }
Exemple #6
0
 public Movil ObtenerPorId(Guid movilId)
 {
     using (var uow = UowFactory.Create <IGestionAdministrativaUow>())
     {
         return(uow.Moviles.Obtener(c => c.Id == movilId));
     }
 }
Exemple #7
0
 public Cliente ObtenerPorId(Guid clienteId)
 {
     using (var uow = UowFactory.Create <ILaPazUow>())
     {
         return(uow.Clientes.Obtener(c => c.Id == clienteId, c => c.Localidad, c => c.Provincia, c => c.CondicionesVenta));
     }
 }
 public LoteFactura UltimoNroLote(Guid opertadorId, int sucursalId)
 {
     using (var uow = UowFactory.Create <ILaPazUow>())
     {
         return(uow.LotesFacturas.Obtener(l => l.OperadorLote == opertadorId && l.NroActual < l.NroHasta && l.Estado == EstadoLoteEnum.Activo && l.SucursalAltaId == sucursalId));
     }
 }
Exemple #9
0
        /// <summary>
        /// A collection with "AutoSave = true" was modified. Write current state to the database
        /// </summary>
        private void OnAutoSaveCollectionChanged(object sender, ReferenceCollectionChangedEventArgs args)
        {
            var instance = args.Parent;
            var property = args.CollectionProperty;

            lock (Graph.GetWrapper(instance.Id)) // Unlike Save AutoSave collections are ALWAYS part of the Graph
            {
                using (var uow = UowFactory.Create())
                {
                    var newResources = ResourceLinker.SaveSingleCollection(uow, instance, property);

                    try
                    {
                        uow.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(LogLevel.Error, ex, "Error saving collection {2} on resource {0}-{1}!", instance.Id, instance.Name, property.Name);
                        throw;
                    }

                    foreach (var newResource in newResources)
                    {
                        AddResource(newResource, true);
                    }
                }
            }
        }
Exemple #10
0
        public void TestConcurrency()
        {
            //client 1 tacking a instance and updating
            UnitOfWork client1Uow     = (UnitOfWork)UowFactory.Create("DefaultConnection");
            var        client1Repo    = client1Uow.GetEntityRepository <Product>();
            var        client1Product = client1Repo.GetById(EntityId);

            //lets detach before saving to simulate detached client behaviour
            client1Uow.Context.ChangeObjectState(client1Product, EntityState.Detached);
            client1Product.Name = "Client 1 new name";

            //client 2 tacking the same instance and updating
            UnitOfWork client2Uow     = (UnitOfWork)UowFactory.Create("DefaultConnection");
            var        client2Repo    = client2Uow.GetEntityRepository <Product>();
            var        client2Product = client2Repo.GetById(EntityId);

            client2Uow.Context.ChangeObjectState(client2Product, EntityState.Detached);
            client2Product.Name = "Client 2 new name";

            //now save the client 1
            client1Repo.InsertOrUpdate(client1Product);
            client1Uow.Commit();

            //now try to save the client 2, this should result in an concurrency exception
            client2Repo.InsertOrUpdate(client2Product);
            client2Uow.Commit();
        }
Exemple #11
0
        public void Save(Resource resource)
        {
            lock (Graph.GetWrapper(resource.Id) ?? _fallbackLock)
            {
                using (var uow = UowFactory.Create())
                {
                    var newResources = new HashSet <Resource>();

                    var entity = ResourceEntityAccessor.SaveToEntity(uow, resource);
                    if (entity.Id == 0)
                    {
                        newResources.Add(resource);
                    }

                    var newInstances = ResourceLinker.SaveReferences(uow, resource, entity);
                    newResources.AddRange(newInstances);

                    try
                    {
                        uow.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(LogLevel.Error, ex, "Error saving resource {0}-{1}!", resource.Id, resource.Name);
                        throw;
                    }

                    foreach (var instance in newResources)
                    {
                        AddResource(instance, true);
                    }
                }
            }
        }
Exemple #12
0
        protected override void OnHandle(AddZoneCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                ZoneTypeCodes zoneTypeCode;
                if (!Enum.TryParse(command.ZoneType, out zoneTypeCode))
                {
                    throw new ArgumentOutOfRangeException($"Zone type: {command.ZoneType} is not valid");
                }

                Validate(command, uow);
                long siteId = command.SiteId;
                var  site   = uow.Context.
                              FindById <Entities.Sites.Site>(siteId);

                var zone = new Entities.Sites.Zone
                {
                    Name        = command.Name,
                    Title       = command.Title,
                    ZoneType    = zoneTypeCode,
                    IsActive    = command.IsActive,
                    IsPrivate   = !command.IsPublic,
                    Site        = site,
                    Description = command.Description,
                };
                uow.Context.Add(zone);

                uow.Complete();
            }
        }
Exemple #13
0
        public ActionResult Index()
        {
            Response.Write(UowFactory.Get() + "<br>");
            Response.Write(UowFactory.Get() + "<br>");
            Response.Write(UowFactory.Get() + "<br>");

            return(View());
        }
Exemple #14
0
 public static void Initialize(TestContext context)
 {
     //Configure the UowFactory to create a new database and seed sample data
     UowFactory.Configure(true, true);
     DeleteDbFile();
     //create the unit of work to be tested
     Uow = (UnitOfWork)UowFactory.CreateUnitOfWork("DefaultConnection");
 }
Exemple #15
0
 public Caja UltimaCajaCarrada(Guid opertadorId, int sucursalId)
 {
     using (var uow = UowFactory.Create <ILaPazUow>())
     {
         return(uow.Cajas.Listado()
                .Where(c => c.FCierre != null && c.OperadorId == opertadorId)
                .OrderByDescending(c => c.FCierre).FirstOrDefault());
     }
 }
Exemple #16
0
        public static IList <StudentPreview> GetList(string sortBy, string sortOrder)
        {
            var repo = new StudentRepository(UowFactory.Get());

            var list = repo.Query()
                       .OrderBy(string.Format("{0} {1}", sortBy ?? "Id", sortOrder))
                       .List();

            return(ModelHelper.FetchList <StudentPreview, Student>(list));
        }
        public string FormaDePagoReimpresion(Guid comprobanteId)
        {
            StringBuilder formaPago = new StringBuilder();

            using (var uow = UowFactory.Create <ILaPazUow>())
            {
                var cajaMovimiento = uow.CajaMovimientos.Obtener(cm => cm.ComprobanteId == comprobanteId);

                if (cajaMovimiento != null)
                {
                    if (cajaMovimiento.Efectivo.HasValue)
                    {
                        formaPago.AppendFormat("Efectivo {0:c2}. ", cajaMovimiento.Efectivo);
                    }

                    if (cajaMovimiento.Tarjeta.HasValue)
                    {
                        //var tarjetasMovimientos =
                        //    uow.TarjetasMovimientos.Listado(tm => tm.Tarjeta).Where(tm => tm.CajaMovimientoId == cajaMovimiento.Id).ToList();

                        //foreach (var tarjetasMovimiento in tarjetasMovimientos)
                        //{
                        //    formaPago.AppendFormat("Tarjeta  {0} {1:c2}. ", tarjetasMovimiento.Tarjeta.Nombre, tarjetasMovimiento.Importe);
                        //}
                        formaPago.AppendFormat("Tarjeta  {0} . ", cajaMovimiento.Tarjeta);
                    }

                    if (cajaMovimiento.Cheque.HasValue)
                    {
                        //var chequesTerceros =
                        //    uow.ChequesTercero.Listado(ch => ch.Banco).Where(ch => ch.CajaMovimientoId == cajaMovimiento.Id);

                        //foreach (var chequeTercero in chequesTerceros)
                        //{
                        //    formaPago.AppendFormat("Cheque  {0} {1:c2}. ", chequeTercero.Banco.Nombre, chequeTercero.Importe);
                        //}
                        formaPago.AppendFormat("Cheque  {0} . ", cajaMovimiento.Cheque);
                    }

                    if (cajaMovimiento.Deposito.HasValue)
                    {
                        //var cuentasMovimientos =
                        //    uow.CuentasMovimientos.Listado(ch => ch.Cuenta).Where(ch => ch.ComprobanteId == comprobanteId);

                        //foreach (var cuentasMovimiento in cuentasMovimientos)
                        //{
                        //    formaPago.AppendFormat("Deposito  {0} {1:c2}. ", cuentasMovimiento.Cuenta.Nombre, cuentasMovimiento.Credito);
                        //}
                        formaPago.AppendFormat("Deposito  {0} . ", cajaMovimiento.Deposito);
                    }
                }
            }

            return(formaPago.ToString());
        }
Exemple #18
0
        protected override void OnHandle(DeletePostSerieCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                Validate(uow, command);
                var postSerie = uow.Context.Query <PostSerie>().SingleOrDefault(j => j.Id == command.Id);
                uow.Context.Remove(postSerie);

                uow.Complete();
            }
        }
        protected override void OnHandle(DeleteJobCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                Validate(uow, command);
                var job = uow.Context.Query <Entities.Jobs.Job>().SingleOrDefault(j => j.Id == command.JobId);
                uow.Context.Remove(job);

                uow.Complete();
            }
        }
        protected override void OnHandle(DeletePostCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                // TODO: validation
                var post = uow.Context.FindById <Entities.Posts.Post>(command.PostId);
                uow.Context.Remove(post);

                uow.Complete();
            }
        }
        protected override void OnHandle(SetUserEmailConfirmCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                var user = uow.Context.FindById <Entities.Security.User>(command.UserId);
                user.EmailConfirm = command.Confirmed;
                uow.Context.Update(user);

                uow.Complete();
            }
        }
        protected override void OnHandle(DeleteCategoryCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                var categoryToDelete = uow.Context.FindById <Entities.Posts.Category>(command.CategoryId);
                Validate(categoryToDelete, uow);

                uow.Context.Remove(categoryToDelete);

                uow.Complete();
            }
        }
Exemple #23
0
        public static void Initialize(TestContext context)
        {
            //Configure the UowFactory to create a new database and seed sample data
            UowFactory.Configure(true, true);
            DeleteDbFile();

            var configurator = new EndpointConfigurator();
            var config       = configurator.Configure(new HttpConfiguration());

            Server = new HttpServer(config);
            Client = new HttpClient(Server);
        }
Exemple #24
0
        protected override void OnHandle(SetSecurityStampCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                var user = uow.Context.FindById <Entities.Security.User>(command.UserId);

                user.SecurityStamp = command.SecurityStamp;
                uow.Context.Update(user);

                uow.Complete();
            }
        }
Exemple #25
0
        public decimal SenaAFavorProveedor(Guid proveedorId, int sucursalId)
        {
            using (var uow = UowFactory.Create <ILaPazUow>())
            {
                var proveedorMontosFavor = uow.ProveedoresSenias.Listado().Where(ps => ps.ProveedorId == proveedorId &&
                                                                                 ps.SucursalAltaId == sucursalId &&
                                                                                 ps.ImporteUsado < ps.Importe)
                                           .ToList();

                return
                    (proveedorMontosFavor.Sum(cm => cm.Importe.GetValueOrDefault() - cm.ImporteUsado.GetValueOrDefault()));
            }
        }
Exemple #26
0
        protected override void OnHandle(DeleteRoleCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                var roleToDelete = uow.Context
                                   .FindById <Entities.Security.Role>(command.Id);

                Validate(uow, roleToDelete);
                uow.Context.Remove(roleToDelete);

                uow.Complete();
            }
        }
        protected override void OnHandle(DeleteSiteCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                var siteToDelete = uow.Context
                                   .FindById <Entities.Sites.Site>(command.Id);

                Validate(uow, siteToDelete);
                uow.Context.Remove(siteToDelete);

                uow.Complete();
            }
        }
Exemple #28
0
        public bool Destroy(IResource resource, bool permanent)
        {
            var instance = (Resource)resource;

            ((IPlugin)resource).Stop();

            // Load entity and relations to disconnect resource and remove from database
            using (var uow = UowFactory.Create())
            {
                var resourceRepository = uow.GetRepository <IResourceEntityRepository>();
                var relationRepository = uow.GetRepository <IResourceRelationRepository>();

                // Fetch entity and relations
                // Update properties on the references and get rid of relation entities
                var entity    = resourceRepository.GetByKey(instance.Id);
                var relations = ResourceRelationAccessor.FromEntity(uow, entity);
                foreach (var relation in relations)
                {
                    var reference = Graph.Get(relation.ReferenceId);

                    ResourceLinker.RemoveLinking(resource, reference);

                    if (permanent)
                    {
                        relationRepository.Remove(relation.Entity);
                    }
                }

                resourceRepository.Remove(entity, permanent);

                uow.SaveChanges();
            }

            // Unregister from all events to avoid memory leaks
            UnregisterEvents(instance);

            // Remove from internal collections
            var removed = Graph.Remove(instance);

            // Notify listeners about the removal of the resource
            if (removed && instance is IPublicResource publicResource)
            {
                RaiseResourceRemoved(publicResource);
            }

            // Destroy the object
            TypeController.Destroy(instance);

            return(removed);
        }
        protected override void OnHandle(ChangePasswordCommand command)
        {
            using (var uow = UowFactory.Create())
            {
                var user = uow.Context.FindById <Entities.Security.User>(command.UserId);

                var newPasswordAlgorithm = (HashAlgorithm)Enum.Parse(typeof(HashAlgorithm), user.PasswordHashAlgorithm);
                user.PasswordHashAlgorithm = command.PasswordHashAlgorithm;
                user.PasswordHash          = command.NewPasswordHash;

                uow.Context.Update(user);

                uow.Complete();
            }
        }
Exemple #30
0
        public void ExecuteInitializer(IResourceInitializer initializer)
        {
            var roots = initializer.Execute(Graph);

            if (roots.Count == 0)
            {
                throw new InvalidOperationException("ResourceInitializer must return at least one resource");
            }

            using (var uow = UowFactory.Create())
            {
                ResourceLinker.SaveRoots(uow, roots);
                uow.SaveChanges();
            }
        }