示例#1
0
        public IHttpActionResult PutEventoResponsable(int id, EventoResponsable eventoResponsable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eventoResponsable.Id)
            {
                return(BadRequest());
            }

            db.Entry(eventoResponsable).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventoResponsableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id)
        {
            EventoResponsable eventoResponsable = db.EventoResponsable.Find(id);

            db.EventoResponsable.Remove(eventoResponsable);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
        public ActionResult Edit(Evento evento, int IdListaDistribucion)
        {
            if (ModelState.IsValid)
            {
                evento.Activo          = true;
                db.Entry(evento).State = EntityState.Modified;
                changeStatus(evento);
                db.SaveChanges();

                //Modify IdSubcategoria inside Ventana object
                var ventana = db.Ventana.Where(v => v.IdEvento == evento.Id).FirstOrDefault();

                if (ventana != null)
                {
                    ventana.IdSubCategoria  = evento.IdSubCategoria;
                    db.Entry(ventana).State = EntityState.Modified;
                    db.SaveChanges();
                }

                if (IdListaDistribucion != 0)
                {
                    // Remove the old asignation
                    var responsables = db.EventoResponsable
                                       .Where(d => d.IdEvento == evento.Id)
                                       .ToList();

                    foreach (var responsable in responsables)
                    {
                        db.EventoResponsable.Remove(responsable);
                    }

                    //Add new asignation
                    var lista = db.ListaDistribucion
                                .Where(x => x.Id == IdListaDistribucion)
                                .Select(x => x.IdPersona)
                                .ToList();

                    foreach (var item in lista)
                    {
                        EventoResponsable eResponsable = new EventoResponsable();
                        eResponsable.IdEvento      = evento.Id;
                        eResponsable.IdResponsable = item;
                        db.EventoResponsable.Add(eResponsable);
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.IdAsignador    = new SelectList(db.Personas.Select(x => new { Id = x.Id, Nombre = x.Nombre + " " + x.Apellido1 + " " + x.Apellido2 }).OrderBy(x => x.Nombre), "Id", "Nombre");
            ViewBag.IdCategoria    = new SelectList(db.Categoria.Select(x => new { Id = x.Id, Nombre = x.Nombre }).OrderBy(x => x.Nombre), "Id", "Nombre", evento.IdCategoria);
            ViewBag.IdSubCategoria = new SelectList(db.SubCategoria.Select(x => new { Id = x.Id, Nombre = x.Nombre }).OrderBy(x => x.Nombre), "Id", "Nombre", evento.IdSubCategoria);
            return(View(evento));
        }
示例#4
0
 public ActionResult Edit([Bind(Include = "Id,IdEvento,IdResponsable")] EventoResponsable eventoResponsable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(eventoResponsable).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.IdResponsable = new SelectList(db.Personas, "Id", "Nombre", eventoResponsable.IdResponsable);
     return(View(eventoResponsable));
 }
示例#5
0
        public IHttpActionResult GetEventoResponsable(int id)
        {
            EventoResponsable eventoResponsable = db.EventoResponsable.Find(id);

            if (eventoResponsable == null)
            {
                return(NotFound());
            }

            return(Ok(eventoResponsable));
        }
示例#6
0
        public IHttpActionResult PostEventoResponsable(EventoResponsable eventoResponsable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.EventoResponsable.Add(eventoResponsable);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = eventoResponsable.Id }, eventoResponsable));
        }
示例#7
0
        public ActionResult Create(Evento evento, int IdOrigen, string IdResponsables)
        {
            if (ModelState.IsValid)
            {
                if (evento.Nota == null)
                {
                    evento.Nota = " ";
                }

                PersonaServicio personaServicio      = new PersonaServicio();
                IRespuestaServicio <Persona> persona = personaServicio.GetPersona(User.Identity.GetUserId());

                if (persona.EjecucionCorrecta)
                {
                    evento.IdAsignador = persona.Respuesta.Id;
                    db.Evento.Add(evento);
                    db.SaveChanges();
                }

                if (IdOrigen > 0)
                {
                    EventoOrigen eOrigen = new EventoOrigen();
                    eOrigen.IdEvento = evento.Id;
                    eOrigen.IdOrigen = IdOrigen;
                    db.EventoOrigen.Add(eOrigen);
                    db.SaveChanges();
                }

                if (IdResponsables != null && IdResponsables != "")
                {
                    Char     delimiter  = ',';
                    String[] substrings = IdResponsables.Split(delimiter);
                    foreach (var substring in substrings)
                    {
                        if (substring != "")
                        {
                            EventoResponsable eResponsable = new EventoResponsable();
                            eResponsable.IdEvento      = evento.Id;
                            eResponsable.IdResponsable = int.Parse(substring);
                            db.EventoResponsable.Add(eResponsable);
                            db.SaveChanges();
                        }
                    }
                    SendNotification(evento, "New Event: ");
                }

                return(RedirectToAction("Index"));
            }

            return(View(evento));
        }
示例#8
0
        // GET: Operaciones/EventoResponsable/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EventoResponsable eventoResponsable = db.EventoResponsable.Find(id);

            if (eventoResponsable == null)
            {
                return(HttpNotFound());
            }
            return(View(eventoResponsable));
        }
示例#9
0
        public IHttpActionResult DeleteEventoResponsable(int id)
        {
            EventoResponsable eventoResponsable = db.EventoResponsable.Find(id);

            if (eventoResponsable == null)
            {
                return(NotFound());
            }

            db.EventoResponsable.Remove(eventoResponsable);
            db.SaveChanges();

            return(Ok(eventoResponsable));
        }
示例#10
0
        // GET: Operaciones/EventoResponsable/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EventoResponsable eventoResponsable = db.EventoResponsable.Find(id);

            if (eventoResponsable == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IdResponsable = new SelectList(db.Personas, "Id", "Nombre", eventoResponsable.IdResponsable);
            return(View(eventoResponsable));
        }
示例#11
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
            {
                string fileName        = file.FileName;
                string fileContentType = file.ContentType;
                byte[] fileBytes       = new byte[file.ContentLength];
                var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));

                using (var package = new ExcelPackage(file.InputStream))
                {
                    PersonaServicio personaServicio      = new PersonaServicio();
                    IRespuestaServicio <Persona> persona = personaServicio.GetPersona(User.Identity.GetUserId());

                    var currentSheet = package.Workbook.Worksheets;

                    foreach (var workSheet in currentSheet)
                    {
                        var noOfCol = workSheet.Dimension.End.Column;
                        var noOfRow = workSheet.Dimension.End.Row;

                        for (var row = 2; row <= noOfRow; row++)
                        {
                            if (workSheet.Cells[row, 1].Value != null)
                            {
                                var    numSubCategoria = workSheet.Cells[row, 3].Value.ToString().Trim();
                                var    fecha           = DateTime.ParseExact(workSheet.Cells[row, 2].Value.ToString().Trim(), "dd/MM/yyyy hh:mm", null);
                                Evento evento          = new Evento();

                                evento.Descripcion    = workSheet.Cells[row, 1].Value == null ? string.Empty : workSheet.Cells[row, 1].Value.ToString().Trim();
                                evento.FechaInicio    = workSheet.Cells[row, 2].Value == null ? DateTime.Now : fecha;
                                evento.FechaFin       = evento.FechaFin.AddHours(1);
                                evento.IdAsignador    = persona.Respuesta.Id;
                                evento.IdCategoria    = db.Categoria.Where(c => c.NombreCorto == "Ventana").Select(c => c.Id).FirstOrDefault();
                                evento.IdSubCategoria = db.SubCategoria.Where(c => c.NombreCorto == numSubCategoria).Select(c => c.Id).FirstOrDefault() == 0
                                    ? db.Carrier.Where(c => c.NombreCorto == "DIMS Nacional").Select(c => c.Id).FirstOrDefault()
                                    : db.SubCategoria.Where(c => c.NombreCorto == numSubCategoria).Select(c => c.Id).FirstOrDefault();
                                evento.Nota   = " ";
                                evento.Activo = true;

                                db.Evento.Add(evento);
                                db.SaveChanges();

                                var proveedor         = workSheet.Cells[row, 4].Value.ToString().Trim();
                                var idSubArea         = db.SubArea.Where(f => f.NombreCorto == proveedor).Select(f => f.Id).FirstOrDefault();
                                var listaDistribucion = db.ListaDistribucion.Where(w => (w.IdSubarea == idSubArea)).Select(w => new { IdPersona = w.IdPersona }).ToList();

                                if (listaDistribucion.Count > 0)
                                {
                                    foreach (var item in listaDistribucion)
                                    {
                                        EventoResponsable eResponsable = new EventoResponsable();
                                        eResponsable.IdEvento      = evento.Id;
                                        eResponsable.IdResponsable = item.IdPersona;
                                        db.EventoResponsable.Add(eResponsable);
                                        db.SaveChanges();
                                    }
                                    SendNotification(evento, "New Event: ");
                                }
                            }
                        }
                        break;
                    }
                    return(RedirectToAction("Index", "Evento", new { Area = "Operaciones" }));
                }
            }
            return(View("Index"));
        }