コード例 #1
0
        public ActionResult UpdateClient(Client client)
        {
            if (ModelState.IsValid)
            {
                CompanyEntities4 db = new CompanyEntities4();

                Client updateClient = (from c in db.Clients
                                       where c.Id_Client == client.Id_Client
                                       select c).FirstOrDefault(); //επέλεξε τον πελάτη απο την παράμετρο που θα σου δωθεί


                if (updateClient != null)
                {
                    updateClient.FirstName  = client.FirstName;
                    updateClient.LastName   = client.LastName;
                    updateClient.Address    = client.Address;
                    updateClient.AFM        = client.AFM;
                    updateClient.Telephone  = client.Telephone;
                    updateClient.Brand_Name = client.Brand_Name;
                    updateClient.DOY        = client.DOY;
                }
                db.SaveChanges();
            }

            return(new EmptyResult());
        }
コード例 #2
0
 public bool IsEmailExist(string emailId)
 {
     using (CompanyEntities4 dc = new CompanyEntities4())
     {
         var v = dc.Vendors.FirstOrDefault(a => a.Email == emailId);
         return(v != null);
     }
 }
コード例 #3
0
        public ActionResult Clients()
        {
            var db = new CompanyEntities4();

            var           us      = User.Identity.Name;                            //Παίρνουμε τα στοιχεία του τρέχων συνδεδεμένου χρήστη(Πώλητη)
            Vendor        vendor  = db.Vendors.FirstOrDefault(c => c.Email == us); // τσεκάρουμε εαν υπάρχει στη λίστα μας
            List <Client> clients = vendor?.Clients.ToList();                      //και πέρνουμε όλα τα στοιχεια των πελατών που αντιστοιχούν στον συγκεκριμένο πωλητή

            return(View(clients));                                                 //view->List->Details
        }
コード例 #4
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Vendor vendor)
        {
            bool   status = false;
            string message;

            // Mode Validation

            if (ModelState.IsValid)
            {
                #region Email already Exists
                var isExist = IsEmailExist(vendor.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exists");
                    return(View(vendor));
                }
                #endregion

                #region  Generate Activation Code
                vendor.ActivationCode = Guid.NewGuid(); // περναει εναν κωδικό στο πεδιο του χρήστη
                #endregion


                #region Password Hashing
                vendor.Password        = Crypto.Hash(vendor.Password);
                vendor.ConfirmPassword = Crypto.Hash(vendor.ConfirmPassword);
                #endregion
                vendor.IsEmailVerified = false;


                #region Save to Database
                using (CompanyEntities4 dc = new CompanyEntities4())
                {
                    dc.Vendors.Add(vendor); //παίρνει τις τιμες από τα texboxes
                    dc.SaveChanges();       //και τα αποθηκευει στη βάση

                    //Send Email to User
                    SendVerificationLinkEmail(vendor.Email, vendor.ActivationCode.ToString());
                    message = "Registration successfully done. Account activation link" +
                              "has been sent to your email id:" + vendor.Email;
                    status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = status;

            return(View(vendor));
        }
コード例 #5
0
        //创建EF 上下文对象,已经存在就直接取 ,不存在就创建,保证线程内是唯一
        public static DbContext Create()
        {
            DbContext dbContext = CallContext.GetData("DbContext") as DbContext;

            if (dbContext == null)
            {
                dbContext = new CompanyEntities4();
                CallContext.SetData("DbContext", dbContext);
            }
            return(dbContext);
        }
コード例 #6
0
        public ActionResult Login(VendorLogin login, string returnUrl = "")
        {
            string message;

            using (CompanyEntities4 dc = new CompanyEntities4())
            {
                //To a.EmailID = είναι το mail που υπαρχει στη βαση μας, Το login.EmailID = είναι το mail που εχει πληκτρολογησει η χρήστης
                var v = dc.Vendors.FirstOrDefault(a => a.Email == login.Email); //επιστρεφει ΟΛΑ τα στοιχεια του χρήστη με το συγκεκριμένο email
                if (v != null && v.IsEmailVerified)                             //εαν υπάρχει αυτό το mail και αρα και ο χρήστης..., και το mail εχει επιβεβαιωθει
                {
                    //Συκρινε το password που πληκτρολογησε ο χρήσης(login.PassWord) με το password που υπάρχει στη βάση(v.PassWord)
                    if (string.CompareOrdinal(Crypto.Hash(login.Password), v.Password) == 0)
                    {
                        //εαν εχει τσεκαριστει το login.Rememberme(TRUE), τοτε ο χρόνος αναμονής θα είναι 525600 αλλιως θα είναι 20 min(να αποσυνδεθεις δηλ σε 20 min)
                        //SOS ΚΡΑΤΑΕΙ ΤΟ SESSION
                        int timeout   = login.RememberMe ? 525600 : 20;                                        //525600 min = 1 year
                        var ticket    = new FormsAuthenticationTicket(login.Email, login.RememberMe, timeout); //το ticket θα εχει ονομα(στην περιπτωση μας το email), εαν θα ειναι μονιμο, και ο χρονος λήξης του
                        var encrypted = FormsAuthentication.Encrypt(ticket);                                   //το κρυπτογραφούμε
                        var cookie    =
                            new HttpCookie(FormsAuthentication.FormsCookieName, encrypted)                     // πέρνουμε μονο το όνομα (το mail στην περιπτωση μας), και την τιμη του(κρυπτογραφημενη)
                        {
                            Expires  = DateTime.Now.AddMinutes(timeout),                                       //ποτε λήγει
                            HttpOnly = true
                        };
                        Response.Cookies.Add(cookie);

                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided1";
                }
            }


            ViewBag.Message = message;

            return(View());
        }
コード例 #7
0
        //έυρεση πελατών

        public JsonResult Client(string id, string name)
        {
            var db = new CompanyEntities4();
            var us = User.Identity.Name;

            if (id == string.Empty && name == string.Empty)
            {
                return(new JsonResult());
            }
            if (id != string.Empty && name == string.Empty)
            {
                int.TryParse(id, out var id1);   //cast σε int

                var query = from v in db.Vendors //inner join * προς *
                            from c in v.Clients
                            where v.Email == us && c.Id_Client == id1
                            select new
                {
                    c.Id_Client,
                    c.FirstName,
                    c.LastName,
                    c.Address,
                    c.AFM,
                    c.Telephone,
                    c.Brand_Name,
                    c.DOY
                };
                return(Json(query, JsonRequestBehavior.AllowGet));
            }
            if (id == string.Empty && name != string.Empty)
            {
                var query2 = from v in db.Vendors
                             from c in v.Clients
                             where v.Email == us && c.LastName == name
                             select new
                {
                    c.Id_Client,
                    c.FirstName,
                    c.LastName,
                    c.Address,
                    c.AFM,
                    c.Telephone,
                    c.Brand_Name,
                    c.DOY
                };
                return(Json(query2, JsonRequestBehavior.AllowGet));
            }

            return(new JsonResult());
        }
コード例 #8
0
        public ActionResult InsertHistory(History history, string clientId)
        {
            if (ModelState.IsValid)
            {
                var db = new CompanyEntities4();
                int.TryParse(clientId, out var id1); //cast σε int

                history.Id_Client = id1;             // ->παιρνει το Id του client και το αποδιδει στη στήλη του orders για να τα αντιστοιχισει
                db.Histories.Add(history);
                db.SaveChanges();                    //αποθήκευσε τις αλλαγές
            }

            return(new EmptyResult());
        }
コード例 #9
0
        public ActionResult FindId()
        {
            var db = new CompanyEntities4();


            var query = (from c in db.Clients
                         orderby c.Id_Client
                         descending
                         select c.Id_Client).FirstOrDefault(); //το βρισκω

            query++;                                           //το προσθετω κατα ενα
            var query2 = query.ToString();                     //το μετατρεπω σε string για να το πάρει το ajax μετα

            return(Content(query2));                           //και το επιστρεφω σε string
        }
コード例 #10
0
        public ActionResult InsertClient(Client client)
        {
            var    db     = new CompanyEntities4();
            var    us     = User.Identity.Name;                            //Παίρνουμε τα στοιχεία του τρέχων συνδεδεμένου χρήστη(Πώλητη)
            Vendor vendor = db.Vendors.FirstOrDefault(c => c.Email == us); // τσεκάρουμε εαν υπάρχει στη λίστα μας

            if (vendor != null)
            {
                client.VendorId = vendor.Id_Vendor; // ->παιρνει το Id του Vendor και το αποδιδει στη στήλη του client για να τα αντιστοιχισει
                db.Clients.Add(client);
            }
            db.SaveChanges(); //αποθήκευσε τις αλλαγές

            return(new EmptyResult());
        }
コード例 #11
0
 public ActionResult DeleteOrders(int ordersId)
 {
     using (CompanyEntities4 db = new CompanyEntities4())
     {
         Order order = (from o in db.Orders
                        where o.Id == ordersId
                        select o).FirstOrDefault();
         if (order == null || ordersId == 0)
         {
             return(new EmptyResult());
         }
         db.Orders.Remove(order);
         db.SaveChanges();
     }
     return(new EmptyResult());
 }
コード例 #12
0
 public ActionResult DeleteClient(int clientId)
 {
     using (CompanyEntities4 db = new CompanyEntities4())
     {
         Client client = (from c in db.Clients
                          where c.Id_Client == clientId
                          select c).FirstOrDefault();
         if (client == null || clientId == 0)
         {
             return(new EmptyResult());
         }
         db.Clients.Remove(client);
         db.SaveChanges();
     }
     return(new EmptyResult());
 }
コード例 #13
0
 public ActionResult DeleteHistory(int historyId)
 {
     using (CompanyEntities4 db = new CompanyEntities4())
     {
         History history = (from h in db.Histories
                            where h.Id == historyId
                            select h).FirstOrDefault();
         if (history == null || historyId == 0)
         {
             return(new EmptyResult());
         }
         db.Histories.Remove(history);
         db.SaveChanges();
     }
     return(new EmptyResult());
 }
コード例 #14
0
        //ευρεση ιστορικου
        public JsonResult ClientHistory(string id, string name)
        {
            var db = new CompanyEntities4();
            var us = User.Identity.Name;

            if (id == string.Empty && name == string.Empty)
            {
                return(new JsonResult());
            }
            if (id != string.Empty && name == string.Empty)
            {
                int.TryParse(id, out var id1);   //cast σε int
                var query = from v in db.Vendors //inner join * προς *
                            from c in v.Clients
                            from h in c.Histories
                            where v.Email == us && c.Id_Client == id1
                            select new
                {
                    h.Id,
                    h.Record,
                    h.Complaints,
                    h.Absence,
                    h.Date,
                    h.Vendor_Name
                };
                return(Json(query, JsonRequestBehavior.AllowGet));
            }
            if (id == string.Empty && name != string.Empty)
            {
                var query2 = from v in db.Vendors  //inner join * προς *
                             from c in v.Clients
                             from h in c.Histories
                             where v.Email == us && c.LastName == name
                             select new
                {
                    h.Id,
                    h.Record,
                    h.Complaints,
                    h.Absence,
                    h.Date,
                    h.Vendor_Name
                };
                return(Json(query2, JsonRequestBehavior.AllowGet));
            }
            return(new JsonResult());
        }
コード例 #15
0
        public ActionResult VerifyAccount(string id) //αυτη η μέθοδος καλείται στη γραμμή 194
        {
            bool status = false;

            using (CompanyEntities4 dc = new CompanyEntities4())
            {
                dc.Configuration.ValidateOnSaveEnabled = false; //this line i have added here to avoid
                //confirm password does not match issue on save changes
                var v = dc.Vendors.FirstOrDefault(a => a.ActivationCode == new Guid(id));
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = status;
            return(View());
        }
コード例 #16
0
        public ActionResult UpdateHistory(History update)
        {
            if (ModelState.IsValid)
            {
                CompanyEntities4 db = new CompanyEntities4();

                History updateHistory = (from c in db.Histories
                                         where c.Id == update.Id
                                         select c).FirstOrDefault(); //επέλεξε τον πελάτη απο την παράμετρο που θα σου δωθεί


                if (updateHistory != null)
                {
                    updateHistory.Record      = update.Record;
                    updateHistory.Complaints  = update.Complaints;
                    updateHistory.Absence     = update.Absence;
                    updateHistory.Date        = update.Date;
                    updateHistory.Vendor_Name = update.Vendor_Name;
                }
                db.SaveChanges();
            }
            return(new EmptyResult());
        }
コード例 #17
0
        public ActionResult UpdateOrders(Order update)
        {
            if (ModelState.IsValid)
            {
                CompanyEntities4 db = new CompanyEntities4();

                Order updateOrder = (from c in db.Orders
                                     where c.Id == update.Id
                                     select c).FirstOrDefault(); //επέλεξε τον πελάτη απο την παράμετρο που θα σου δωθεί


                if (updateOrder != null)
                {
                    updateOrder.Date_order  = update.Date_order;
                    updateOrder.Medicine    = update.Medicine;
                    updateOrder.Quantity    = update.Quantity;
                    updateOrder.Vendor_Name = update.Vendor_Name;
                    updateOrder.Unit_Price  = update.Unit_Price;
                    updateOrder.Order_Cost  = update.Order_Cost;
                }
                db.SaveChanges();
            }
            return(new EmptyResult());
        }
コード例 #18
0
        //ευρεση παραγγελιων
        public JsonResult ClientOrders(string id, string name, string date)
        {
            var db = new CompanyEntities4();
            var us = User.Identity.Name;

            if (id == string.Empty && name == string.Empty && date == string.Empty)
            {
                return(new JsonResult());
            }
            if (id != string.Empty && name == string.Empty && date == string.Empty)
            {
                int.TryParse(id, out var id1);   //cast σε int
                var query = from v in db.Vendors //inner join * προς *
                            from c in v.Clients
                            from o in c.Orders   //inner join 1 προς *
                            where v.Email == us && c.Id_Client == id1
                            select new
                {
                    o.Id,
                    o.Date_order,
                    o.Medicine,
                    o.Quantity,
                    o.Vendor_Name,
                    o.Unit_Price,
                    o.Order_Cost
                };
                return(Json(query, JsonRequestBehavior.AllowGet));
            }
            if (id == string.Empty && name != string.Empty && date == string.Empty)
            {
                var query2 = from v in db.Vendors //inner join * προς *
                             from c in v.Clients
                             from o in c.Orders   //inner join 1 προς *
                             where v.Email == us && c.LastName == name
                             select new
                {
                    o.Id,
                    o.Date_order,
                    o.Medicine,
                    o.Quantity,
                    o.Vendor_Name,
                    o.Unit_Price,
                    o.Order_Cost
                };
                return(Json(query2, JsonRequestBehavior.AllowGet));
            }
            if (id != string.Empty && name == string.Empty && date != string.Empty)
            {
                try
                {
                    var toparse = DateTime.ParseExact(date, "dd/MM/yyyy", null); //cast σε date
                    int.TryParse(id, out var id1);                               //cast σε int
                    var query = from v in db.Vendors
                                from c in v.Clients
                                from o in c.Orders
                                where v.Email == us && o.Date_order == toparse && c.Id_Client == id1
                                select new
                    {
                        o.Id,
                        o.Date_order,
                        o.Medicine,
                        o.Quantity,
                        o.Vendor_Name,
                        o.Unit_Price,
                        o.Order_Cost
                    };
                    return(Json(query, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    //ThrowJsonError(e);
                    //return new JsonResult();
                    return(Json(e, JsonRequestBehavior.AllowGet));
                }
            }
            return(new JsonResult());
        }