예제 #1
0
        /// <summary>
        /// Creer Nouvelle Conversation
        /// </summary>
        /// <param name="newChat"></param>
        /// <returns></returns>
        public bool SaveChat (Chat newChat) {
            using (var db = new StationContext()) {

                if(newChat.Persons.Count < 2)
                    throw new InvalidOperationException("CONVERSATION_MUST_HAVE_AT_LEAST_TWO_PERSONS");

                if(newChat.ChatGuid==Guid.Empty)
                    newChat.ChatGuid=Guid.NewGuid();

                newChat.DateAdded        =DateTime.Now;
                newChat.AddUserGuid      =Guid.Empty;
                newChat.LastEditUserGuid =Guid.Empty;
                newChat.LastEditDate     =DateTime.Now;

                //foreach (var talker in newConversation.Persons)
                //{
                //    if(talker.PersonGuid==Guid.Empty)
                //        talker.PersonGuid=Guid.NewGuid();
                //    db.Set<Person>().Add(talker);
                //}

                foreach(var talk in newChat.Messages.Where(talk => talk.MessageGuid==Guid.Empty))
                    talk.MessageGuid=Guid.NewGuid();
                db.Set<Chat>().Add(newChat);      
                return db.SaveChanges()>0;
            }
        }
예제 #2
0
 /// <summary>
 /// La list des Documents d'une Personne
 /// </summary>
 /// <param name="personGuid"></param>
 /// <param name="maxResult"></param>
 /// <returns></returns>
 public IEnumerable GetPersonDocuments(Guid personGuid, int maxResult = 7)
 {
     using (var db = new StationContext()) {
         return (db.Set<Person>().Find(personGuid).Documents).Select(
                 d => new Document {DocumentGuid = d.DocumentGuid, DocumentName = d.DocumentName, Description = d.Description, FileType = d.FileType }).OrderBy(d=> d.DateAdded);                
     }
 }
예제 #3
0
 /// <summary>
 /// Represente un enseignant, proff, staff, qui a la possibilite de se connecter a l'Eschool
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 //[PrincipalPermission(SecurityAction.Demand, Role = Clearances.StaffWrite)]
 public bool SaveDocument (Document document) {                      
     using (var db = new StationContext()) {
         if(document.DocumentGuid==Guid.Empty)
             document.DocumentGuid=Guid.NewGuid();
         
         db.Set<Document>().Add(document);
         return db.SaveChanges()>0;
     }
 }
예제 #4
0
        public bool Put(FuelPrelevement myPrelevement)
        {
            using (var db = new StationContext())
            {
                myPrelevement.LastEditDate = DateTime.Now;

                db.Set<FuelPrelevement>().Attach(myPrelevement);
                db.Entry(myPrelevement).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
예제 #5
0
        public bool UpdateStaff(Staff mStaff)
        {
            using (var db = new StationContext())
            {
                db.Staffs.Attach(mStaff);
                db.Entry(mStaff).State = EntityState.Modified;

                db.Set<Person>().Attach(mStaff.Person);
                db.Entry(mStaff.Person).State = EntityState.Modified;

                return db.SaveChanges() > 0;
            }
        }
예제 #6
0
        /// <summary>
        /// Envoyer Un Chat
        /// </summary>
        /// <param name="newMessage"></param>
        /// <returns></returns>
        public bool PushChat (Message newMessage) {
            using (var db = new StationContext()) {
                if(db.Set<Person>().Find(newMessage.SenderGuid)==null)
                    throw new InvalidOperationException("SENDER_REFERENCE_NOT_FOUND");
                if(newMessage.MessageGuid==Guid.Empty)
                    newMessage.MessageGuid=Guid.NewGuid();
                if(db.Set<Chat>().Find(newMessage.ChatGuid)==null)
                    throw new InvalidOperationException("CONVERSATION_REFERENCE_NOT_FOUND");

                newMessage.DateAdded        =DateTime.Now;
                newMessage.AddUserGuid      = Guid.Empty;
                newMessage.LastEditUserGuid = Guid.Empty;
                newMessage.LastEditDate     =DateTime.Now;
                
                if (newMessage.Attachement == null) return db.SaveChanges() > 0;

                if(newMessage.Attachement.DocumentGuid==Guid.Empty)
                    newMessage.Attachement.DocumentGuid=Guid.NewGuid();
                db.Set<Document>().Add(newMessage.Attachement);
                db.Set<Message>().Add(newMessage);

                return db.SaveChanges()>0;
            }
        }
예제 #7
0
        public async Task<bool> AddStaff(Staff myStaff)
        {
            using (var db = new StationContext())
            {
                if (myStaff.StaffGuid == Guid.Empty)
                    myStaff.StaffGuid = Guid.NewGuid();
                if (myStaff.Person.PersonGuid == Guid.Empty)
                    myStaff.Person.PersonGuid = Guid.NewGuid();

                await myStaff.Person.Validate();

                db.Set<Person>().Add(myStaff.Person);
                db.Staffs.Add(myStaff);
                return await db.SaveChangesAsync() > 0;
            }
        }
예제 #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="myCustomer"></param>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.StaffWrite)]
        public bool UpdateCustomer(Customer myCustomer)
        {
            using (var db = new StationContext())
            {
                // ReSharper disable once PossibleNullReferenceException
                var userTrace = (Guid)Membership.GetUser().ProviderUserKey;                
                myCustomer.LastEditDate = DateTime.Now;
                myCustomer.LastEditUserGuid = userTrace;

                db.Customers.Attach(myCustomer);
                db.Entry(myCustomer).State = EntityState.Modified;

                db.Set<Person>().Attach(myCustomer.Person);
                db.Entry(myCustomer.Person).State = EntityState.Modified;

                return db.SaveChanges() > 0;
            }
        }
예제 #9
0
        public async Task<bool> Post(Fuel myFuel)
        {
            using (var db = new StationContext())
            {              
                if (myFuel.FuelGuid == Guid.Empty) myFuel.FuelGuid = Guid.NewGuid();

                myFuel.DateAdded = DateTime.Now;
                myFuel.LastEditDate = DateTime.Now;

                db.Fuels.Add(myFuel);
                if (!myFuel.Prices.Any()) return db.SaveChanges() > 0;

                if (myFuel.Prices.First().PriceGuid == Guid.Empty) myFuel.Prices.First().PriceGuid = Guid.NewGuid();
                myFuel.Prices.First().ProductGuid = myFuel.FuelGuid;
                myFuel.Prices.First().FromDate = DateTime.Now;
                db.Set<Price>().Add(myFuel.Prices.First());

                return await db.SaveChangesAsync() > 0;
            }
        }        
예제 #10
0
        public async Task<bool> Post(FuelPrelevement myPrelevement)
        {
            using (var db = new StationContext())
            {
                if (myPrelevement.PrelevementGuid == Guid.Empty) myPrelevement.PrelevementGuid = Guid.NewGuid();

                var citerneGuid = db.Pompes.Find(myPrelevement.PompeGuid).CiterneGuid;
                if (citerneGuid != null)
                    myPrelevement.CiterneGuid = (Guid)citerneGuid;
                else
                    throw new ArgumentException("CAN_NOT_FIND_CITERNE");
               
                myPrelevement.CurrentPrice = (await FuelManager.GetFuelCurrentPrice(db.Pompes.Find(myPrelevement.PompeGuid).Citerne.FuelGuid));

                myPrelevement.DateAdded = DateTime.Now;
                myPrelevement.LastEditDate = DateTime.Now;

                db.Set<FuelPrelevement>().Add(myPrelevement);
                return await db.SaveChangesAsync() > 0;
            }
        }
예제 #11
0
        /// <summary>
        /// Represente un client
        /// </summary>
        /// <param name="newCustomer"></param>
        /// <exception cref="InvalidOperationException">CAN_NOT_CREAT_STAFF_PROFILE</exception>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.CustomerWrite)]
        public bool AddCustomer(Customer newCustomer) 
        {
            Guard.WhenArgument(newCustomer.Person.FullName, "CUSTOMER_NAME_CAN_NOT_BE_EMPTY").IsNullOrEmpty().IsEqual("Inconnue").Throw();

            using (var db = new StationContext())
            {
                if (newCustomer.CustomerGuid == Guid.Empty)
                    newCustomer.CustomerGuid = Guid.NewGuid();
                if (newCustomer.Person.PersonGuid == Guid.Empty)
                    newCustomer.Person.PersonGuid = Guid.NewGuid();

                // ReSharper disable once PossibleNullReferenceException
                var userTrace = (Guid) Membership.GetUser().ProviderUserKey;
                newCustomer.DateAdded = DateTime.Now;
                newCustomer.AddUserGuid = userTrace;
                newCustomer.LastEditDate = DateTime.Now;
                newCustomer.LastEditUserGuid = userTrace;

                db.Set<Person>().Add(newCustomer.Person);
                db.Customers.Add(newCustomer);
                return db.SaveChanges() > 0;
            }
        }
예제 #12
0
 public FuelPrelevement GetPrelevement(Guid prelevGuid)
 {
     using (var db = new StationContext())
         return db.Set<FuelPrelevement>().Find(prelevGuid);
 }
예제 #13
0
        public async Task<bool> Post(Price newPrice)
        {
            using (var db = new StationContext())
            {
                if (!db.Fuels.Any(f => f.FuelGuid == newPrice.ProductGuid))
                    throw new InvalidOperationException("FUEL_REFERENCE_NOT_FOUND");

                if (newPrice.PriceGuid == Guid.Empty) newPrice.PriceGuid = Guid.NewGuid();

                newPrice.DateAdded = DateTime.Now;
                newPrice.LastEditDate = DateTime.Now;

                db.Set<Price>().Add(newPrice);
                return await db.SaveChangesAsync() > 0;
            }
        }
예제 #14
0
 public Person GetPerson(Guid personGuid)
 {
     using (var db = new StationContext())
         return db.Set<Person>().Find(personGuid);
 }
예제 #15
0
 /// <summary>
 /// Telecharger un document
 /// </summary>
 /// <param name="documentGuid"></param>
 /// <returns></returns>
 public Document DownloadDocument (Guid documentGuid) {
     using (var db = new StationContext()) {
         return db.Set<Document>().Find(documentGuid);
     }
 }
예제 #16
0
 /// <summary>
 /// Supprimer definitivement un document
 /// </summary>
 /// <returns></returns>
 //[PrincipalPermission(SecurityAction.Demand, Role = Clearances.StaffDelete)]
 public bool DeleteDocument (Guid documentGuid) {
     using (var db = new StationContext()) {
         db.Set<Document>().Remove(db.Set<Document>().Find(documentGuid));
         return db.SaveChanges()>0;               
     }
 }
예제 #17
0
        /// <summary>
        /// Return les nationalites des etudiants ainsi que des staffs
        /// </summary>
        /// <returns></returns>
        public IEnumerable AllNationalities()
        {
            var nationalities = new List<string>();

            using (var db = new StationContext())
                nationalities.AddRange(db.Set<Person>().Select(p => p.Nationality).ToList());

            if (nationalities.Count != 0) return nationalities.Distinct();

            nationalities.Add("Maroc");
            nationalities.Add("Mali");
            nationalities.Add("US");
            nationalities.Add("France");
            nationalities.Add("Senegal");
            nationalities.Add("Algerie");
            nationalities.Add("Liberia");
            nationalities.Add("Guinee");
            nationalities.Add("Afrique Du Sud");
            nationalities.Add("Nigeria");
            nationalities.Add("Soudan");
            nationalities.Add("Gambie");
            nationalities.Add("Congo");
            nationalities.Add("Burkina Fasso");

            return nationalities.Distinct();
        }
예제 #18
0
 /// <summary>
 /// Supprimer un chat
 /// </summary>
 /// <param name="chatGuid"></param>
 /// <returns></returns>
 public bool DeleteChat (Guid chatGuid) {
     using (var db = new StationContext()) {
         var oldConversation = db.Set<Chat>().Find(chatGuid);
         oldConversation.IsDeleted=true;
         oldConversation.DeleteUserGuid=Guid.Empty;
         db.Set<Chat>().Attach(oldConversation);
         db.Entry(oldConversation).State=EntityState.Modified;
         return db.SaveChanges()>0;
     }
 }
예제 #19
0
        /// <summary>
        /// Envoyer Un Message
        /// </summary>
        /// <param name="conversation"></param>
        /// <returns></returns>
        public bool SendMessage(Conversation conversation)
        {
            using (var db = new StationContext()) {
                if(db.Set<Person>().Find(conversation.SenderGuid)==null)
                    throw new InvalidOperationException("SENDER_REFERENCE_NOT_FOUND");
                if (conversation.MessageGuid == Guid.Empty) conversation.MessageGuid = Guid.NewGuid();
                if(conversation.RecipientGuid==conversation.SenderGuid)
                    throw new InvalidOperationException("MESSAGE_SENDER_CAN_NOT_EGUAL_RECIPIENT");

                switch (conversation.MessageType)
                {
                    case MessageType.Personal:                      
                        if(db.Set<Person>().Find(conversation.RecipientGuid)==null)
                            throw new InvalidOperationException("RECIPIENT_REFERENCE_NOT_FOUND");                      
                        break;

                    case MessageType.Email:
                        if(string.IsNullOrEmpty(conversation.RecipientEmail))
                            conversation.RecipientEmail=db.Set<Person>().Find(conversation.RecipientGuid).EmailAdress;
                        if( !InputHelper.IsValidEmail(conversation.RecipientEmail))
                            throw new InvalidOperationException("RECIPIENT_EMAIL_INVALID");
                        


                        var newMail = new MailMessage();                        
                        newMail.To.Add(new MailAddress(conversation.RecipientEmail));
                        newMail.Subject  = conversation.Subject;
                        newMail.Body     = conversation.Content;

                        if (EmailHelper.SendMailByGmail(newMail))
                        {
                            conversation.DateAdded=DateTime.Now;
                            conversation.LastEditDate=DateTime.Now;
                            db.Conversations.Add(conversation);
                            return db.SaveChanges()>0;
                        }
                        return false;
                                                                  
                    //case MessageType.ToClasse:                       
                    //    if(db.Classes.Find(conversation.RecipientGuid)==null)
                    //        throw new InvalidOperationException("CLASSE_REFERENCE_NOT_FOUND");
                    //    break;
                }
                
                conversation.DateAdded    =DateTime.Now;
                conversation.LastEditDate =DateTime.Now;

                db.Conversations.Add(conversation);
                if (conversation.Attachement != null)                
                   db.Set<Document>().Add(conversation.Attachement);
                return db.SaveChanges()>0;
            }
        }
예제 #20
0
 /// <summary>
 /// Telecharger Attachement associer au message
 /// </summary>
 /// <param name="messageGuid"></param>
 /// <returns></returns>
 public Document DownloadAttachement (Guid messageGuid) {
     using (var db = new StationContext())
         return db.Set<Message>().Find(messageGuid).Attachement;
 }
예제 #21
0
 /// <summary>
 /// La liste des messages d'une personne
 /// </summary>
 /// <param name="personGuid"></param>
 /// <param name="fromDate"></param>
 /// <param name="toDate"></param>
 /// <param name="maxResult"></param>
 /// <returns></returns>
 public IEnumerable<ChatCard> GetChats (Guid personGuid, DateTime? fromDate = null, DateTime? toDate = null, int maxResult = 20) {
     using (var db = new StationContext()) {
         if(fromDate==null||toDate==null) {
             fromDate=DateTime.Today;
             toDate=DateTime.Today.AddDays(1);
         }
        
         return db.Set<Person>().Find(personGuid).Chats
                                .Where(c=>c.IsDeleted&&(c.DateAdded>=fromDate&&c.DateAdded<=toDate))
                                .OrderByDescending(m => m.DateAdded)
                                .Take(maxResult)
                                .ToList()
                                .Select(c => new ChatCard(c))
                                .ToList();
     }
 }
예제 #22
0
        /// <summary>
        /// Charger un chat avec ses messages
        /// </summary>
        /// <param name="chatGuid"></param>
        /// <param name="toDate"></param>
        /// <param name="maxChats"></param>
        /// <param name="markRead"></param>
        /// <param name="fromDate"></param>
        /// <returns></returns>
        public IEnumerable<MessageCard> GetMessages (Guid chatGuid, DateTime? fromDate = null, DateTime? toDate = null, int maxChats = 20, bool markRead = true) {
            //todo markRead
            using (var db = new StationContext()) {
                if(fromDate==null||toDate==null) {
                    fromDate=DateTime.Today;
                    toDate=DateTime.Today.AddDays(1);
                }

            return
                    db.Set<Chat>().Find(chatGuid).Messages
                                          .Where(c => c.IsDeleted&&(c.DateAdded>=fromDate&&c.DateAdded<=toDate))
                                          .OrderByDescending(c => c.DateAdded)
                                          .Take(maxChats)                       
                                          .ToList()
                                          .Select(c => new MessageCard(c));
            }
        }