コード例 #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;
         }
     }
 }
コード例 #2
0
 public string IsUserExist(Login login)//אם יש כזה משתמש
 {
     using (db = new storesEntities())
     {
         try
         {
             Store ss = db.Stores.Where(s => s.Email == login.Email).FirstOrDefault();
             if (ss != null)
             {
                 if (ss.PasswordUser == login.PasswordUser)
                 {
                     return("" + ss.StoreID);
                 }
                 else
                 {
                     return("no password");
                 }
             }
             else
             {
                 return("no user");
             }
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
コード例 #3
0
 public StoreDTO GetUserById(int id)
 {
     using (db = new storesEntities())
     {
         return(st.ToDTO(db.Stores.Where(s => s.StoreID == id).FirstOrDefault()));
     }
 }
コード例 #4
0
        public List <ClothDTO> GetInventoryById(int id)
        {
            InventoryService InventoryService = new InventoryService();
            List <ClothDTO>  retval           = default;

            try
            {
                using (db = new storesEntities())
                {
                    var list = db.Inventories.Where(inv => inv.StoreID == id).Select(i => i.ClothID).ToList();
                    if (list != null)
                    {
                        retval = new List <ClothDTO>();
                        List <Cloth> listcloth = db.Clothes.Where(c => list.Contains(c.ClothID)).Select(cloth => cloth).ToList <Cloth>();
                        foreach (var item in listcloth)
                        {
                            ClothDTO c = new ClothDTO();
                            c             = c.ToDTO(item);
                            c.CompanyName = InventoryService.GetCompanyNameById(c.CompanyId);
                            retval.Add(c);
                        }
                    }
                    return(retval);
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
コード例 #5
0
        public List <ClothDTO> GetInventory()
        {
            List <ClothDTO> retval = new List <ClothDTO>();

            using (DB = new storesEntities())
            {
                try
                {
                    var list = DB.Clothes.Select(i => i).ToList <Cloth>();
                    if (list != null)
                    {
                        ClothDTO dto = new ClothDTO();
                        foreach (var item in list)
                        {
                            ClothDTO cloth = dto.ToDTO(item);
                            cloth.CompanyName = GetCompanyNameById(cloth.CompanyId);
                            retval.Add(cloth);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw;
                }
                return(retval);
            }
        }
コード例 #6
0
 public string GetCompanyNameById(int id)
 {
     using (DB = new storesEntities())
     {
         return(DB.Companys.Where(com => com.CompanyID == id).First().CompanyName);
     }
 }
コード例 #7
0
        public List <StoreDTO> FindStores(SearcClothDTO search)
        {
            StoreDTO SDTO = new StoreDTO();

            try
            {
                List <InventoryDTO> list   = new List <InventoryDTO>();
                List <StoreDTO>     retval = new List <StoreDTO>();
                int compID   = 0;
                int clothcod = 0;
                using (db = new storesEntities())
                {
                    var company = db.Companys.SingleOrDefault(comp => comp.CompanyName == search.CompanyName);
                    if (company != null)
                    {
                        compID = company.CompanyID;
                    }
                    var cloth = db.Clothes.SingleOrDefault(c => c.ClothCompaniCod == search.ClothCompaniCod && c.CompanyId == compID);
                    if (cloth != null)
                    {
                        clothcod = cloth.ClothID;
                    }
                    list = db.Inventories.Where(i => i.ClothID == clothcod).Select(inve => new InventoryDTO()
                    {
                        ClothID = inve.ClothID, StoreID = inve.StoreID, YearOfProduction = inve.YearOfProduction
                    }).ToList <InventoryDTO>();
                    foreach (var item in list)
                    {
                        var record = db.Stores.Where(store => store.StoreID == item.StoreID).FirstOrDefault();
                        if (record != null)
                        {
                            retval.Add(SDTO.ToDTO(record));
                        }
                    }
                    return(retval);
                }
                //using (db = new storesEntities())
                //{
                //    int ComId = db.Companys.Where(com => com.CompanyName == search.CompanyName).First().CompanyID;//קוד החברה
                //                                                                                                  //קוד הבגד הרצוי
                //    int ClothId = db.Clothes.Where(c => c.Describe == search.Describe && c.Color == search.Color && c.ClothID == search.ClothId && c.CompanyId == ComId).First().ClothID;

                //    List<int> AllStoresId = db.InventoryCloth.Where(inv => inv.ClothId == ClothId).ToList<int>();//הקודים של כל החנויות שיש להם את הבגד
                //    List<Store> AllStores = db.Stores.Where(s => AllStoresId.Where(f => f == s.StoreID).Count() != 0).ToList<Store>();//כל החנויות שיש להם את הבגד
                //    List<StoreDTO> RetList=new List<StoreDTO>();
                //    foreach (Store ss in AllStores)
                //    {
                //        RetList.Add(SDTO.ToDTO(ss));
                //    }
                //    return RetList;
                //}
            }
            catch (Exception e)
            {
                throw;
            }
        }
コード例 #8
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)));
     }
 }
コード例 #9
0
 public DateTime GetlatestDateOfPostBySubjectId(int subjectId)
 {
     using (db = new storesEntities())
     {
         try
         {
             return((DateTime)db.Posts.Where(x => x.SubjectID == subjectId).OrderByDescending(s => s.DatetimeOfWriting).FirstOrDefault().DatetimeOfWriting);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
コード例 #10
0
 public int GetIDOfNewestSubject()
 {
     using (db = new storesEntities())
     {
         try
         {
             return(db.Posts.OrderByDescending(s => s.DatetimeOfWriting).FirstOrDefault().SubjectID);
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
コード例 #11
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;
            }
        }
コード例 #12
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;
         }
     }
 }
コード例 #13
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;
         }
     }
 }
コード例 #14
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;
         }
     }
 }
コード例 #15
0
 public List <ArticlesDTO> GetArticles()
 {
     try
     {
         using (DB = new storesEntities())
         {
             var list = DB.Articles.Select(a => a).ToList <Article>();
             List <ArticlesDTO> retval = new List <ArticlesDTO>();
             foreach (var item in list)
             {
                 retval.Add(new ArticlesDTO().ToDTO(item));
             }
             return(retval);
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
コード例 #16
0
 public List <BillsDTO> GetAllBillsById(int storeId)
 {
     using (db = new storesEntities())
     {
         try
         {
             return(db.Bills.Where(b => b.StoreID == storeId).Select(bb => new BillsDTO()
             {
                 BillID = bb.BillID,
                 StoreId = bb.StoreID,
                 BillPath = bb.BillPath,
                 BilDate = bb.BilDate
             }).ToList <BillsDTO>());
         }
         catch (Exception)
         {
             throw;
         }
     }
 }
コード例 #17
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;
            }
        }
コード例 #18
0
 public List <BillsDTO> SearchBillsInRange(DateTime d1, DateTime d2)
 {
     try
     {
         using (db = new storesEntities())
         {
             BillsDTO        bdto    = new BillsDTO();
             List <BillsDTO> retList = new List <BillsDTO>();
             List <Bill>     billl   = db.Bills.Where(b => b.BilDate >= d1 && b.BilDate <= d2).OrderBy(o => o.BilDate).ToList <Bill>();
             foreach (Bill x in billl)
             {
                 retList.Add(bdto.ToDTO(x));
             }
             return(retList);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #19
0
 public List <PostDTO> GetListOfPostByIdSubject(int idOfSubject)
 {
     using (db = new storesEntities())
         try
         {               //מחקתי הצהרת משתנה
                         //Subject l = db.Subjects.Last();
             return(db.Posts.
                    Where(p => p.SubjectID == idOfSubject)
                    .Select(p => new PostDTO
             {
                 PostID = p.PostID,
                 StoreID = p.StoreID,
                 ContentText = p.ContentText,
                 DatetimeOfWriting = p.DatetimeOfWriting,
                 Title = p.Title
             }).ToList());
         }
         catch (Exception ex)
         {
             LogException(ex);
             return(null);
         }
 }
コード例 #20
0
 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);
 }
コード例 #21
0
        public List <ForListDTO> GetListOfSubjects()
        {
            using (db = new storesEntities())
            {
                try

                {               //מחקתי הצהרת משתנה
                                //Subject l = db.Subjects.Last();
                    return(db.Subjects.
                           Join(db.Stores, sub => sub.StoreID, st => st.StoreID,
                                (sub, st) => new { sub, st })
                           .OrderBy(s => s.sub.DatetimeOfWriting).Select(m => new ForListDTO
                    {
                        ID = m.sub.SubjectID,
                        ImportantText = m.sub.SubjectName,
                        sideText = m.st.StoreName
                    }).ToList());
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #22
0
 public SubjectDTO GetSubjectByID(int ID)
 {
     using (db = new storesEntities())
     {
         try
         {
             return(db.Subjects
                    .Where(x => x.SubjectID == ID)
                    .Select(x => new SubjectDTO()
             {
                 SubjectID = x.SubjectID,
                 SubjectName = x.SubjectName,
                 DatetimeOfWriting = x.DatetimeOfWriting,
                 IfWantUpdate = x.IfWantUpdate,
                 StoreID = x.StoreID,
                 Content = x.Content
             }).FirstOrDefault());
         }
         catch (Exception)
         {
             throw;
         }
     }
 }