private void insertUserToBook(reserva reserva, string emplid) { usuario_reserva usuarioReserva = new usuario_reserva(); usuarioReserva.emplid = emplid; usuarioReserva.reserva_id = reserva.id; reserva.usuario_reserva.Add(usuarioReserva); db.SaveChanges(); }
public void SendMail(reserva reserva, string templatePath) { var username = ReservasUsuarioJaveriana.Lib.Util.GetUserLogged(); var usuarioLDAP = ReservasUsuarioJaveriana.Lib.LDAPQuery.getUserByUID(username); var query = from book in db.vReservas where book.id == reserva.id select book; var res = query.FirstOrDefault<vReserva>(); var body = this.PopulateBody(res.id.ToString(), usuarioLDAP.CN, res.nombre, string.Format("{0:MMMM dd, yyyy}", res.fecha_inicio), res.hora_inicial.ToString() + " - " + res.hora_final.ToString(), templatePath); var message = new MailMessage(); message.To.Add(new MailAddress(usuarioLDAP.MAIL)); //replace with valid value message.Subject = "Reserva " + res.nombre + " - MiPC"; message.Body = body; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { smtp.Send(message); } }
private void insertResourceToBook(reserva reserva, int resourceId) { recurso recurso = db.recursoes.Find(resourceId); if (recurso != null) { reserva.recursoes.Add(recurso); db.SaveChanges(); } else throw new Exception("No se encontro el recurso de la reserva"); }
public reserva insert(Book book) { reserva reserva = new reserva(); using (var transaction = db.Database.BeginTransaction()) { try { var horaFinal = 0; horaFinal = (Convert.ToInt32(book.StartTime) + Convert.ToInt32(book.Duration) * 100); if (horaFinal >= 2400) horaFinal = 2359; var day = (int)book.BookDate.DayOfWeek; //var username = HttpContext.Current.User.Identity.Name.ToString().Split('@')[0]; var username = ReservasUsuarioJaveriana.Lib.Util.GetUserLogged(); reserva.fecha_inicio = book.BookDate; reserva.fecha_final = book.BookDate; reserva.dia = Convert.ToByte(day); reserva.hora_inicial = Convert.ToInt16(book.StartTime); reserva.hora_final = Convert.ToInt16(horaFinal); reserva.tipo_reserva = "1"; reserva.emplid = username; reserva.fecha_registro = DateTime.Now; db.reservas.Add(reserva); db.SaveChanges(); this.insertResourceToBook(reserva, Convert.ToInt32(book.Application)); this.insertUserToBook(reserva, username); transaction.Commit(); return reserva; } catch (Exception) { transaction.Rollback(); throw; } } }