Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "AppointmentId,Date,startHour,state")] Appointment appointment)
        {
            appointment.state = state.Waiting;

            if (ModelState.IsValid)
            {
                db.Appointments.Add(appointment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appointment));
        }
Ejemplo n.º 2
0
        public void SendToRoom(string roomName, string message)
        {
            try
            {
                using (var db = new EpioneContext())
                {
                    var user = db.Users.Where(u => u.UserName == IdentityName).FirstOrDefault();
                    var room = db.Rooms.Where(r => r.Name == roomName).FirstOrDefault();

                    // Create and save message in database
                    Message msg = new Message()
                    {
                        Content   = Regex.Replace(message, @"(?i)<(?!img|a|/a|/img).*?>", String.Empty),
                        Timestamp = DateTime.Now.Ticks.ToString(),
                        FromUser  = user,
                        ToRoom    = room
                    };
                    db.Messages.Add(msg);
                    db.SaveChanges();

                    // Broadcast the message
                    var messageViewModel = Mapper.Map <Message, MessageViewModel>(msg);
                    Clients.Group(roomName).newMessage(messageViewModel);
                }
            }
            catch (Exception)
            {
                Clients.Caller.onError("Message not send!");
            }
        }
Ejemplo n.º 3
0
        public void DeleteRoom(string roomName)
        {
            try
            {
                using (var db = new EpioneContext())
                {
                    // Delete from database
                    var room = db.Rooms.Where(r => r.Name == roomName && r.UserAccount.UserName == IdentityName).FirstOrDefault();
                    db.Rooms.Remove(room);
                    db.SaveChanges();

                    // Delete from list
                    var roomViewModel = _Rooms.First <RoomViewModel>(r => r.Name == roomName);
                    _Rooms.Remove(roomViewModel);

                    // Move users back to Lobby
                    Clients.Group(roomName).onRoomDeleted(string.Format("Room {0} has been deleted.\nYou are now moved to the Lobby!", roomName));

                    // Tell all users to update their room list
                    Clients.All.removeChatRoom(roomViewModel);
                }
            }
            catch (Exception)
            {
                Clients.Caller.onError("Can't delete this chat room.");
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            EpioneContext ec      = new EpioneContext();
            Address       adresse = new Address {
                country = "a", city = "b", Street = "c"
            };

            ec.Address.Add(adresse);
            ec.SaveChanges();
        }
 public ActionResult Approuver(int? id)
 {
     // Appointment A = Ga.RetournerById(id);
     // A.statut = 1;
     Appointment A = ec.Appointments.Find(id);
     ec.Appointments.Attach(A);
     A.statut = 1;
     ec.SaveChanges();
     return RedirectToAction("Index2");
 }
Ejemplo n.º 6
0
        public void CreateRoom(string roomName)
        {
            try
            {
                using (var db = new EpioneContext())
                {
                    // Accept: Letters, numbers and one space between words.
                    Match match = Regex.Match(roomName, @"^\w+( \w+)*$");
                    if (!match.Success)
                    {
                        Clients.Caller.onError("Invalid room name!\nRoom name must contain only letters and numbers.");
                    }
                    else if (roomName.Length < 5 || roomName.Length > 20)
                    {
                        Clients.Caller.onError("Room name must be between 5-20 characters!");
                    }
                    else if (db.Rooms.Any(r => r.Name == roomName))
                    {
                        Clients.Caller.onError("Another chat room with this name exists");
                    }
                    else
                    {
                        // Create and save chat room in database
                        var user = db.Users.Where(u => u.UserName == IdentityName).FirstOrDefault();
                        var room = new Room()
                        {
                            Name        = roomName,
                            UserAccount = user
                        };
                        db.Rooms.Add(room);
                        db.SaveChanges();

                        if (room != null)
                        {
                            // Update room list
                            var roomViewModel = Mapper.Map <Room, RoomViewModel>(room);
                            _Rooms.Add(roomViewModel);
                            Clients.All.addChatRoom(roomViewModel);
                        }
                    }
                }//using
            }
            catch (Exception ex)
            {
                Clients.Caller.onError("Couldn't create chat room: " + ex.Message);
            }
        }
Ejemplo n.º 7
0
 public void Commit()
 {
     dataContext.SaveChanges();
 }
        public ActionResult Upload()
        {
            if (Request.Files.Count > 0)
            {
                try
                {
                    var file = Request.Files[0];

                    // Some basic checks...
                    if (file != null && !FileValidator.ValidSize(file.ContentLength))
                    {
                        return(Json("File size too big. Maximum File Size: 500KB"));
                    }
                    else if (FileValidator.ValidType(file.ContentType))
                    {
                        return(Json("This file extension is not allowed!"));
                    }
                    else
                    {
                        // Save file to Disk
                        var fileName = DateTime.Now.ToString("yyyymmddMMss") + "_" + Path.GetFileName(file.FileName);
                        var filePath = Path.Combine(Server.MapPath("~/Content/uploads/"), fileName);
                        file.SaveAs(filePath);

                        string htmlImage = string.Format(
                            "<a href=\"/Content/uploads/{0}\" target=\"_blank\">" +
                            "<img src=\"/Content/uploads/{0}\" class=\"post-image\">" +
                            "</a>", fileName);

                        using (var db = new EpioneContext())
                        {
                            // Get sender & chat room
                            var senderViewModel = ChatHub._Connections.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
                            var sender          = db.Users.Where(u => u.UserName == senderViewModel.Username).FirstOrDefault();
                            var room            = db.Rooms.Where(r => r.Name == senderViewModel.CurrentRoom).FirstOrDefault();

                            // Build message
                            Message msg = new Message()
                            {
                                Content   = Regex.Replace(htmlImage, @"(?i)<(?!img|a|/a|/img).*?>", String.Empty),
                                Timestamp = DateTime.Now.Ticks.ToString(),
                                FromUser  = sender,
                                ToRoom    = room
                            };

                            db.Messages.Add(msg);
                            db.SaveChanges();

                            // Send image-message to group
                            var messageViewModel = Mapper.Map <Message, MessageViewModel>(msg);
                            var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                            hub.Clients.Group(senderViewModel.CurrentRoom).newMessage(messageViewModel);
                        }

                        return(Json("Success"));
                    }
                }
                catch (Exception ex)
                { return(Json("Error while uploading" + ex.Message)); }
            }

            return(Json("No files selected"));
        } // Upload