예제 #1
0
        public MyResponse Add([FromBody] ServicioViewModel ServicioAgregar)
        {
            MyResponse Res = new MyResponse();

            try
            {
                if (ServicioAgregar != null)
                {
                    var resultado = db.clientes.FirstOrDefault(p => p.Id == ServicioAgregar.fk_Cliente.Id);


                    Models.Servicios oServicio = new Models.Servicios();
                    oServicio.valorxHora     = ServicioAgregar.valorxHora;
                    oServicio.nombreServicio = ServicioAgregar.nombreServicio;
                    oServicio.fk_Cliente     = resultado;

                    db.servicios.Add(oServicio);
                    db.SaveChanges();
                    Res.Success = 1;
                }
                else
                {
                    Res.Message = "Sericio Nulo";
                }
            }
            catch (Exception e)
            {
                Res.Success = 0;
                Res.Message = e.Message;
            }
            return(Res);
        }
예제 #2
0
        public FrmServicio()
        {
            InitializeComponent();
            Model = ServiceLocator.Instance.Resolve <ServicioViewModel>();

            btnNuevo.Visible     = CurrentSession.PermisoUsuario("16");
            btnModificar.Visible = CurrentSession.PermisoUsuario("17");
            btnEliminar.Visible  = CurrentSession.PermisoUsuario("18");
        }
예제 #3
0
        public ActionResult Edit(ServicioViewModel servicioViewModel)
        {
            using (UnidadDeTrabajo <Servicio> unidad = new UnidadDeTrabajo <Servicio>(new BDContext()))
            {
                unidad.genericDAL.Update(this.Convertir(servicioViewModel));
                unidad.Complete();
            }

            return(RedirectToAction("Index"));
        }
예제 #4
0
        }// FIN DE CONVERTIR

        private Servicio Convertir(ServicioViewModel servicioViewModel)
        {
            Servicio ServicioViewModel = new Servicio
            {
                Servicio_ID = servicioViewModel.Servicio_ID,
                Nombre      = servicioViewModel.Nombre,
                Precio      = servicioViewModel.Precio
            };

            return(ServicioViewModel);
        }
예제 #5
0
        // GET: Servicio
        private ServicioViewModel Convertir(Servicio servicio)
        {
            ServicioViewModel servicioViewModel = new ServicioViewModel
            {
                Servicio_ID = servicio.Servicio_ID,
                Nombre      = servicio.Nombre,
                Precio      = (double)servicio.Precio
            };

            return(servicioViewModel);
        }// FIN DE CONVERTIR
        public IActionResult Upsert(int?id)
        {
            servicioViewModel = new ServicioViewModel()
            {
                Servicio           = new Servicio(),
                ListadoCategorias  = _unitOfWork.categoria.ObtenerListadoCategoriasParaDropDown(),
                ListadoFrecuencias = _unitOfWork.frecuencia.ObtenerListadoFrecuenciasParaDropDown(),
            };

            if (id != null)
            {
                // El usuario requiere editar el servicio
                servicioViewModel.Servicio = _unitOfWork.servicio.Get(id.GetValueOrDefault());
            }

            return(View(servicioViewModel));
        }
        public bool UpdateServicio(ServicioViewModel servicioViewModel)
        {
            try
            {
                Servicio s1 = context.servicios.Find(servicioViewModel.ServicioId);
                s1.Cost              = servicioViewModel.Cost;
                s1.Description       = servicioViewModel.Description;
                s1.Name              = servicioViewModel.Name;
                s1.ServiceCategory   = context.categories.Where(x => x.CategoryName == servicioViewModel.CategoryName).First();
                s1.ServiceCategoryId = s1.ServiceCategory.ServiceCategoryId;

                context.Update(s1);
                context.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }
            return(true);
        }
예제 #8
0
        public MyResponse Modificar([FromBody] ServicioViewModel ServicioModificar, int id)
        {
            MyResponse Res = new MyResponse();

            try
            {/*
              * db.Entry(ClienteModificar).State = EntityState.Modified;
              * db.SaveChanges();*/
                var ServicioExistente = db.servicios.FirstOrDefault(p => p.Id == ServicioModificar.Id);

                if (ServicioExistente != null)
                {
                    if (id == ServicioModificar.Id)
                    {
                        ServicioExistente.nombreServicio = ServicioModificar.nombreServicio;
                        ServicioExistente.valorxHora     = ServicioModificar.valorxHora;

                        db.SaveChanges();
                        Res.Success = 1;
                    }
                    else
                    {
                        Res.Success = 0;
                        Res.Message = "Error Diferentes Servicios";
                    }
                }
                else
                {
                    Res.Success = 0;
                    Res.Message = "Error cliente nulo";
                }
            }
            catch (Exception e)
            {
                Res.Success = 0;
                Res.Message = e.Message;
            }
            return(Res);
        }
 public ActionResult Put([FromBody] ServicioViewModel servicioViewModel)
 {
     return(Ok(
                servicioService.UpdateServicio(servicioViewModel)
                ));
 }
예제 #10
0
 public MyResponse Add([FromBody] ServicioViewModel model)
 {
     return(_servicioService.Add(model));
 }
 public bool UpdateServicio(ServicioViewModel servicioViewModel)
 {
     return(servicioRepository.UpdateServicio(servicioViewModel));
 }