Ejemplo n.º 1
0
 public bool AddSubject(SubjectDTO subjectDTO)
 {
     using (db = new storesEntities())
     {
         subjectDTO.DatetimeOfWriting = DateTime.Now;
         try
         {
             db.Subjects.Add(subjectDTO.FromDTO());
             db.SaveChanges();
             return(true);
         }
         catch (DbEntityValidationException e)
         {
             foreach (var eve in e.EntityValidationErrors)
             {
                 Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                   eve.Entry.Entity.GetType().Name, eve.Entry.State);
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                       ve.PropertyName, ve.ErrorMessage);
                 }
             }
             throw;
         }
     }
 }
Ejemplo n.º 2
0
        public void changevotes(int PostID, int updateNumOfVotes)
        {
            Post _myItem = db.Posts.Where(x => x.PostID == PostID).SingleOrDefault();
            var  typ     = typeof(Post);

            typ.GetProperties().ToList().ForEach(m => m.SetValue(_myItem, updateNumOfVotes, null));
            db.SaveChanges();
        }
Ejemplo n.º 3
0
        public bool SaveClothes(List <List <InventoryDTO> > data)
        {
            List <InventoryDTO> minus = data[0];
            List <InventoryDTO> plus  = data[1];

            try
            {
                InventoryDTO inv = new InventoryDTO();
                using (DB = new storesEntities())
                {
                    foreach (var item in plus)
                    {
                        try
                        {
                            DB.Inventories.Add(inv.FromDTO(item));
                            DB.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            throw;
                        }
                    }
                    foreach (var item in minus)
                    {
                        try
                        {
                            Inventory obj = DB.Inventories.Where(i => i.ClothID == item.ClothID).FirstOrDefault();
                            DB.Inventories.Remove(obj);
                            DB.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            throw;
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 4
0
 public List <BillsDTO> UpLoad(string filePath, string fileName)
 {
     using (db = new storesEntities())
     {
         Bill b = new Bill();
         b.BilDate  = DateTime.Now;
         b.BillPath = filePath;
         b.StoreID  = Convert.ToInt32(fileName);
         db.Bills.Add(b);
         db.SaveChanges();
         return(GetAllBillsById(Convert.ToInt32(fileName)));
     }
 }
Ejemplo n.º 5
0
 public bool AddPost(PostDTO postDTO)
 {
     using (db = new storesEntities())
     {
         postDTO.DatetimeOfWriting = DateTime.Now;
         try
         {
             db.Posts.Add(postDTO.FromDTO());
             db.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Ejemplo n.º 6
0
 public bool DeleteFile(string path)
 {
     using (db = new storesEntities())
     {
         try
         {
             Bill b = db.Bills.First(bi => bi.BillPath == path);
             db.Bills.Remove(b);
             db.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
Ejemplo n.º 7
0
 public int AddStore(StoreDTO storeDTO)
 {
     using (db = new storesEntities())
     {
         try
         {
             if (db.Stores.Where(w => w.Email == storeDTO.Email).FirstOrDefault() == null)
             {
                 db.Stores.Add(storeDTO.FromDTO());
                 db.SaveChanges();
                 return(db.Stores.Where(s => s.Email == storeDTO.Email && s.PasswordUser == storeDTO.PasswordUser).FirstOrDefault().StoreID);
             }
             return(0);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Ejemplo n.º 8
0
        public bool ResetPassword(string email)
        {
            //הגרלת מספר חדש
            string NewPassword = Membership.GeneratePassword(6, 1);

            try
            {
                using (db = new storesEntities())
                {
                    while (db.Stores.Where(ss => ss.PasswordUser == NewPassword).Count() != 0)
                    {
                        NewPassword = Membership.GeneratePassword(6, 1);
                    }

                    var result = db.Stores.SingleOrDefault(b => b.Email == email);
                    if (result != null)
                    {
                        result.PasswordUser = NewPassword;
                        db.SaveChanges();
                    }


                    string Id       = "*****@*****.**";
                    string Password = "******";

                    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                    client.EnableSsl             = true;
                    client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new NetworkCredential(Id, Password);
                    MailMessage m = new MailMessage(Id, email, "stores מהאתר ", "הסיסמא החדשה: " + NewPassword);
                    client.Send(m);
                    return(true);
                }
            }
            catch (Exception e)
            {
                //  ResetPassword(email);
                throw e;
            }
        }
 public bool UpdateDetails(StoreDTO store)
 {
     try
     {
         using (db = new storesEntities())
         {
             //  Store sst = db.Stores.Where(ss => ss.StoreID == store.StoreID).FirstOrDefault();
             var result = db.Stores.SingleOrDefault(b => b.StoreID == store.StoreID);
             if (result != null && !result.Equals(store))
             {
                 Store check = db.Stores.Where(w => w.Email == store.Email).FirstOrDefault();
                 if (check.StoreID == store.StoreID)
                 {
                     result.Cell           = store.Cell;
                     result.cellOftheStore = store.cellOftheStore;
                     result.Address        = store.Address;
                     result.Email          = store.Email;
                     result.City           = store.City;
                     result.PasswordUser   = store.PasswordUser;
                     result.ManagerName    = store.ManagerName;
                     result.StoreName      = store.StoreName;
                     db.SaveChanges();
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(false);
 }