예제 #1
0
        protected void AddIncidence(object sender, EventArgs e)
        {
            try
            {

                var newIncidence = new Incidence
                {
                    Id = Guid.NewGuid(),
                    UserId = new Guid(cmdUsuario.SelectedValue),
                    UserName = cmdUsuario.SelectedItem.Text,
                    DateCreation = DateTime.Now,
                    IncidenceTitle = txtTitle.Text,
                    Priority = (EnumIncidencePriority)Enum.Parse(typeof(EnumIncidencePriority), cmbPriority.SelectedItem.Text),
                    Status = (EnumIncidenceStatus)Enum.Parse(typeof(EnumIncidenceStatus), cmbStatus.SelectedItem.Text)
                };

                if(string.IsNullOrWhiteSpace(cmbEquipment.SelectedValue)) throw new Exception("El equipo seleccionado no es válido!");
                var equipment = _equipmentService.GetById(new Guid(cmbEquipment.SelectedValue));
                newIncidence.Equipment = equipment;

                _service.Add(newIncidence);
                _dbContext.SaveChanges();
                Response.Redirect("~/App/Admin/IncidenceList.aspx");
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.Message;
                lblResult.Visible = true;
            }
        }
예제 #2
0
 /// <summary>
 /// Permite añdir una Incidencia
 /// </summary>
 /// <param name="incidence">entidad incidence</param>       
 /// <returns>La incidencia añadida</returns>
 public Incidence Add(Incidence incidence)
 {
     try
     {
         var newClient = _dbContext.Incidences.Add(incidence);
         _dbContext.SaveChanges();
         return newClient;
     }
     catch (Exception ex)
     {
         throw new Exception("Error al añadir la Incidencia: " + ex.InnerException.Message);
     }
 }
예제 #3
0
        /// <summary>
        /// Permite editar una Incidencia
        /// </summary>
        /// <param name="incidence">entidad</param>    
        /// <returns>La incidencia editada</returns>
        public Incidence Update(Incidence incidence)
        {
            try
            {
                var editIncidence = _dbContext.Incidences.FirstOrDefault(i => i.Id == incidence.Id);
                if(editIncidence == null) throw new Exception("Incidencia no encontrada");
                editIncidence.IncidenceTitle = incidence.IncidenceTitle;
                editIncidence.Equipment = incidence.Equipment;
                editIncidence.Priority = incidence.Priority;
                editIncidence.Status = incidence.Status;
                editIncidence.UserId = incidence.UserId;
                editIncidence.UserName = incidence.UserName;
                _dbContext.SaveChanges();
                return editIncidence;
            }

            catch (Exception ex)
            {
                throw new Exception("Error al Editar la Incidencia: " + ex.InnerException.Message);
            }
        }