public async Task <IActionResult> Crear([FromBody] MasterFileContent item)
        {
            try
            {
                var r = await this.Repositorio.MasterFileContent.AddAsync(item);

                await this.Repositorio.CompleteAsync();

                var obj = new
                {
                    ok = true,
                    masterFileContent = r
                };

                return(Created("", obj));
            }
            catch (Exception ex)
            {
                return(BadRequest(new
                {
                    ok = false,
                    mensaje = "Se produjo un error al crear el registro",
                    errors = new { mensaje = ex.Message }
                }));
            }
        }
        public async Task <IActionResult> Actualizar([FromBody] MasterFileContent itemNuevo, int id, int idm)
        {
            try
            {
                itemNuevo.Id = id;


                var itemEncontrado = await this.Repositorio.MasterFileContent.GetByIdAsync(id);

                if (itemEncontrado == null)
                {
                    return(BadRequest(new { ok = false, mensaje = "No se encontró el registro a actulizar", erros = "" }));
                }

                itemEncontrado.Map(itemNuevo);

                var r = this.Repositorio.MasterFileContent.Update(itemEncontrado);
                await this.Repositorio.CompleteAsync();

                // var item = await this.Repositorio.MasterFileContent.GetContenidoById(id);

                var master = await this.Repositorio.MasterFile.GetByIdAsync(idm);

                //obtener los nuevos totales
                var listaActual = await this.Repositorio.MasterFileContent.GetContenido(idm);

                var totalInc = listaActual.Where(x => x.Incluido == true).Sum(x => x.Total);
                var totalAdd = listaActual.Where(x => x.Incluido == false).Sum(x => x.Total);

                master.TotalAdicional = totalAdd;
                master.TotalIncluido  = totalInc;
                master.TotalMaster    = totalInc + totalAdd;

                var rm = this.Repositorio.MasterFile.Update(master);
                await this.Repositorio.CompleteAsync();

                var obj = new
                {
                    ok        = true,
                    contenido = r,
                    master    = master
                };

                return(Created("", obj));
            }
            catch (Exception ex)
            {
                return(BadRequest(new
                {
                    ok = false,
                    mensaje = "Se produjo un error al Actualizar el registro",
                    errors = new { mensaje = ex.Message }
                }));
            }
        }
Exemple #3
0
 public static void Map(this MasterFileContent itemDb, MasterFileContent item)
 {
     itemDb.PrecioUnitario = item.PrecioUnitario;
     itemDb.Cantidad       = item.Cantidad;
     itemDb.Total          = item.Total;
     itemDb.Img            = item.Img;
     //itemDb.Divisa = item.Divisa;
     //itemDb.DivisaId = item.DivisaId;
     itemDb.TieneImagen = item.TieneImagen;
     itemDb.OcRealizado = item.OcRealizado;
     itemDb.OcRequerido = item.OcRequerido;
     itemDb.Incluido    = item.Incluido;
     itemDb.Nota        = item.Nota;
     itemDb.Nota2       = item.Nota2;
     itemDb.Nota3       = item.Nota3;
 }
        public async Task <IActionResult> Crear([FromBody] MasterFile item)
        {
            try
            {
                //1) obtener los datos de la agenda
                var ra = await this.Repositorio.Agendas.GetByIdAsync(item.AgendaId);

                var paq = await this.Repositorio.Paquetes.GetByIdAsync(ra.PaqueteId);

                //2) Crear registro de master file
                item.Divisa = paq.Divisa;
                var m = await this.Repositorio.MasterFile.AddAsync(item);

                await this.Repositorio.CompleteAsync();

                //3) obtener los registros del paquete
                var listaIncluidos = await this.Repositorio.PaquetesServicios.FindAsyc(x => x.PaqueteId == ra.PaqueteId);

                //4)  agregarlos como incluidos = true al masterfile content
                List <MasterFileContent> listaContenido = new List <MasterFileContent>();

                var totalIncluido = 0m;
                foreach (var incluido in listaIncluidos)
                {
                    MasterFileContent mfc = new MasterFileContent();
                    mfc.Id             = 0;
                    mfc.MasterFileId   = m.Id;
                    mfc.ServicioId     = incluido.ServicioId;
                    mfc.PrecioUnitario = incluido.PrecioUnitario;
                    mfc.Cantidad       = incluido.Cantidad;
                    mfc.Total          = incluido.Total;
                    mfc.Img            = null;
                    //mfc.DivisaId = m.DivisaId;
                    mfc.TieneImagen = false;
                    mfc.OcRealizado = false;
                    mfc.OcRequerido = false;
                    mfc.Incluido    = true;

                    totalIncluido += incluido.Total;

                    listaContenido.Add(mfc);
                }

                //5) guardar contenido
                await this.Repositorio.MasterFileContent.AddRangeAsync(listaContenido);

                m.TotalIncluido = totalIncluido;
                m.TotalMaster   = totalIncluido;
                await this.Repositorio.CompleteAsync();


                var obj = new
                {
                    ok         = true,
                    masterfile = m
                };

                return(Created("", obj));
            }
            catch (Exception ex)
            {
                return(BadRequest(new
                {
                    ok = false,
                    mensaje = "Se produjo un error al crear el registro",
                    errors = new { mensaje = ex.Message }
                }));
            }
        }
        public async Task <IActionResult> RegistrarAdicionales(int h, int idm, [FromBody] int[] lista)
        {
            try
            {
                // obtener los servicios que estan en el array
                var listaServicios = await this.Repositorio.Servicios.GetServicioInclude(h, lista);

                var master = await this.Repositorio.MasterFile.GetByIdAsync(idm);

                //
                List <MasterFileContent> listaContenido = new List <MasterFileContent>();

                foreach (var serv in listaServicios)
                {
                    MasterFileContent mfc = new MasterFileContent();

                    mfc.Id             = 0;
                    mfc.MasterFileId   = master.Id;
                    mfc.ServicioId     = serv.Id;
                    mfc.PrecioUnitario = serv.PrecioSugerido;
                    mfc.Cantidad       = 1;
                    mfc.Total          = serv.PrecioSugerido;
                    mfc.Img            = null;
                    //mfc.DivisaId = master.DivisaId;
                    mfc.TieneImagen = false;
                    mfc.OcRealizado = false;
                    mfc.OcRequerido = false;
                    mfc.Incluido    = false;

                    listaContenido.Add(mfc);
                }

                // Guardar contenido
                await this.Repositorio.MasterFileContent.AddRangeAsync(listaContenido);

                await this.Repositorio.CompleteAsync();

                // Actualizar los totales

                var listaActual = await this.Repositorio.MasterFileContent.GetContenido(idm);

                var totalInc = listaActual.Where(x => x.Incluido == true).Sum(x => x.Total);
                var totalAdd = listaActual.Where(x => x.Incluido == false).Sum(x => x.Total);

                master.TotalAdicional = totalAdd;
                master.TotalIncluido  = totalInc;
                master.TotalMaster    = totalInc + totalAdd;

                var r = this.Repositorio.MasterFile.Update(master);

                await this.Repositorio.CompleteAsync();

                // OK
                var obj = new
                {
                    ok        = true,
                    contenido = listaActual,
                    master    = master
                };

                return(Ok(obj));
            }
            catch (Exception ex)
            {
                return(BadRequest(new
                {
                    ok = false,
                    mensaje = "Se produjo un error al Actualizar el registro",
                    errors = new { mensaje = ex.Message }
                }));
            }
        }