Ejemplo n.º 1
0
        public void UpdateOrderDetails(OrderDetailsView orderDetails)

        {
            try
            {
                using (Entities context = new Entities())
                {
                    var ordert = context.Set <OrdersTbl>().Find(orderDetails.OrderNumber);
                    //ניתן לשנות הזמנה בסטטוס חדש בלבד
                    if (ordert.OrderStatus != 11)
                    {
                        throw new Exception("לא ניתן לשנות את ההזמנה. אנא פנה למנהל הכלביה");
                    }


                    context.Entry(ordert).CurrentValues.SetValues(orderDetails);
                    context.SaveChanges();
                    if (orderDetails.UserEmail != string.Empty)
                    {
                        //שליחת מייל למשתמש
                        SendMailService sendMailService = new SendMailService();
                        SendMailRequest mailRequest     = new SendMailRequest();
                        mailRequest.recipient = orderDetails.UserEmail;

                        mailRequest.subject = "מצב הזמנה - " + orderDetails.OrderNumber + "מקום טוב- יוסף טוויטו";
                    }
                }
            }
            catch (SqlException ex)
            { throw ex; }
            finally
            { }
        }
Ejemplo n.º 2
0
        //הכנסת הזמנה
        public int createOrder(OrderDetailsView orderDetailsView)
        //  public int CreateOrder()

        {
            //Userservice userservice = new Userservice();
            //OrderDetailsView orderDetailsView = new OrderDetailsView();
            //orderDetailsView.Userid = 1;
            //orderDetailsView.FromDate = new DateTime(2018, 11, 01);
            //orderDetailsView.ToDate = new DateTime(2018, 11, 30);
            //orderDetailsView.ShiftNumberFrom = 1;
            //orderDetailsView.ShiftNumberTo = 2;
            //orderDetailsView.User = new UserDetailsView();
            //orderDetailsView.User.UserEmail = "*****@*****.**";
            //orderDetailsView.userFirstName = "איריס";
            //orderDetailsView.userLastName = "זרצקי";
            //orderDetailsView.mDogs = new List<DogsInOrderView>();
            //orderDetailsView.mDogs.Add(new DogsInOrderView());
            //orderDetailsView.mDogs.Add(new DogsInOrderView());
            //orderDetailsView.mDogs[0].DogNumber = 4;
            //orderDetailsView.mDogs[0].Training = true;
            //orderDetailsView.mDogs[1].DogNumber = 3;
            OrdersTbl ordersTbl = new OrdersTbl();

            //if(orderDetailsView.mDogs.Count==2)
            //     ordersTbl.Price = CalculateOrderPrice(orderDetailsView);

            decimal result = checkForAnotherParallelOrder(orderDetailsView);  //אין הזמנות חופפות לאותם כלבים

            if (result >= 0)
            {
                ordersTbl.OrderStatus     = 11;
                ordersTbl.OrderUserId     = orderDetailsView.Userid;
                ordersTbl.OrderType       = 1;
                ordersTbl.FromDate        = orderDetailsView.FromDate;
                ordersTbl.ShiftNumberFrom = orderDetailsView.ShiftNumberFrom;
                ordersTbl.ToDate          = orderDetailsView.ToDate;
                ordersTbl.ShiftNumberTo   = orderDetailsView.ShiftNumberTo;
                ordersTbl.OrderCreateDate = DateTime.Now;
                if (orderDetailsView.mDogs.Count > 2)
                {
                    ordersTbl.Price = -999;  //יותר מ 2 כלבים. מחיר ינתן בתיאום עם יוסף
                }
                else
                {
                    if (orderDetailsView.Price == 0)
                    {
                        ordersTbl.Price = result;
                    }
                }
                if (orderDetailsView.Discount > 0)
                {
                    ordersTbl.discount = orderDetailsView.Discount;
                }
                else
                {
                    ordersTbl.discount = 0;
                }
                // List<OrderDetailsView> list = checkForAnotherParallelOrder(orderDetailsView);


                for (int i = 0; i < orderDetailsView.mDogs.Count; i++)
                {
                    //if (orderDetailsView.mDogs[i].Training)

                    //{
                    DogsInOrder dogsInOrder = new DogsInOrder();
                    dogsInOrder.DogTraining = orderDetailsView.mDogs[i].DogTraining;
                    dogsInOrder.DogNumber   = orderDetailsView.mDogs[i].DogNumber;

                    dogsInOrder.HomeFood = orderDetailsView.mDogs[i].HomeFood;

                    dogsInOrder.Status = 21; //פעיל בהזמנה, אם יבוטל ישתנה הקוד ל 23
                    ordersTbl.DogsInOrder.Add(dogsInOrder);
                    //}
                }


                context.OrdersTbl.Add(ordersTbl);
                context.SaveChanges();
                //שליפת מספר ההזמנה שנוצרה
                result = GetLastOrder(orderDetailsView.Userid);
                if (orderDetailsView.UserEmail != string.Empty)
                {
                    //שליחת מייל למשתמש
                    SendMailService sendMailService = new SendMailService();
                    SendMailRequest mailRequest     = new SendMailRequest();
                    mailRequest.recipient = orderDetailsView.UserEmail;
                    mailRequest.subject   = "קליטת הזמנה - " + (int)result + "מקום טוב- יוסף טוויטו";
                    mailRequest.body      = " הזמנתך נקלטה";

                    sendMailService.SendMail(mailRequest);
                    //שליחת מייל ליוסף
                    SendMailService sendMailServiceMT = new SendMailService();
                    SendMailRequest mailRequestMT     = new SendMailRequest();
                    mailRequest.recipient = "*****@*****.**";
                    mailRequest.subject   = " קליטת הזמנה  - " + (int)result + "מקום טוב- יוסף טוויטו";
                    mailRequest.body      = string.Format(" הזמנה מלקוח {0} נקלטה במערכת ", orderDetailsView.userFirstName + " " + orderDetailsView.userLastName);
                    mailRequest.body     += "\n";
                    mailRequest.body     += string.Format("מתאריך {0} , משמרת {1} עד תאריך {2} , משמרת {3}", ((DateTime)ordersTbl.FromDate).ToShortDateString(), ordersTbl.ShiftNumberFrom, ((DateTime)ordersTbl.ToDate).ToShortDateString(), ordersTbl.ShiftNumberTo);
                    mailRequest.body     += "\n";
                    mailRequest.body     += string.Format("מספר כלבים בהזמנה - {0}", ordersTbl.DogsInOrder.Count);
                    sendMailService.SendMail(mailRequest);
                }
            }
            return((int)result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// עדכון / הוספת הזמנות על-ידי מנהל
        /// </summary>
        /// <param name="OrdersList"></param>
        public void UpdateOrdersByManager(List <OrderDetailsViewManager> OrdersList)
        {
            int update = 0;

            try
            {
                using (Entities context = new Entities())
                {
                    foreach (OrderDetailsViewManager order in OrdersList)
                    {
                        var ordert = context.Set <OrdersTbl>().Find(order.OrderNumber);

                        if (ordert != null)
                        {
                            if (!EqualsOrders(order, ordert))
                            {
                                context.Entry(ordert).CurrentValues.SetValues(order);

                                foreach (DogsInOrderView dog in order.mDogs)
                                {
                                    var dogt = context.Set <DogsInOrder>().Find(order.OrderNumber, dog.DogNumber);
                                    if (dog.Status == 21)
                                    {
                                        context.Entry(dogt).CurrentValues.SetValues(dog);
                                    }
                                    else
                                    if (dog.Status == 23)
                                    {
                                        context.DogsInOrder.Remove(dogt);
                                        RoomsServie roomsServie = new RoomsServie();
                                        roomsServie.RemoveDogFromFutureRoomSetting(dog); //הוצאת כלב שבוטל מהחדרים בהזמנות עתידיות
                                        if (ordert.DogsInOrder.Count == 0)
                                        {
                                            context.OrdersTbl.Remove(ordert);
                                            update = 1; //ההזמנה בוטלה בגלל שאין כלבים בהזמנה
                                        }
                                        else
                                        {
                                            update = 2;
                                        }
                                    }
                                }
                                context.SaveChanges();
                                if (order.UserEmail != string.Empty)
                                {
                                    //שליחת מייל למשתמש
                                    SendMailService sendMailService = new SendMailService();
                                    SendMailRequest mailRequest     = new SendMailRequest();
                                    mailRequest.recipient = order.UserEmail;

                                    mailRequest.subject = "מצב הזמנה - " + order.OrderNumber + "מקום טוב- יוסף טוויטו";
                                    if (update == 1)
                                    {
                                        mailRequest.body = " ההזמנה בוטלה בגלל שאין כלבים בהזמנה";
                                    }
                                    else if (update == 2)
                                    {
                                        mailRequest.body = " ביטול הכלב מההזמנה בוצע";
                                    }
                                    else if (order.OrderStatus == 12)
                                    {
                                        mailRequest.body = " הזמנתך אושרה";
                                    }
                                    else if (order.OrderStatus == 15)
                                    {
                                        mailRequest.body = "לצערינו לא נוכל לבצע אילוף, ולכן הזמנתך אושרה ללא אילוף";
                                    }
                                    else if (order.OrderStatus == 13)
                                    {
                                        mailRequest.body = "לצערינו לא נוכל לאשר את ההזמנה , לפרטים נוספים פנה למנהל הפנסיון";
                                    }

                                    sendMailService.SendMail(mailRequest);
                                }
                            }
                        }

                        else
                        {
                            createOrder(order);
                        }
                    }
                    context.Dispose();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public void  SendMail(SendMailRequest mail)
        {
            // mail.recipient=mailRequestValues.First()
            MailMessage msg = new MailMessage();

            // Separate the recipient array
            string[] emailAddress = mail.recipient.Split(',');

            foreach (string currentEmailAddress in emailAddress)
            {
                msg.To.Add(new MailAddress(currentEmailAddress.Trim()));
            }

            // Separate the cc array , if not null
            string[] ccAddress = null;

            if (mail.cc != null)
            {
                ccAddress = mail.cc.Split(',');
                foreach (string currentCCAddress in ccAddress)
                {
                    msg.CC.Add(new MailAddress(currentCCAddress.Trim()));
                }
            }
            // Include the file attachment if the filename is not null
            if (mail.filename != null)
            {
                string[] files = mail.filename.Split(',');
                // Declare a temp file path where we can assemble our file
                foreach (string currentfiles in files)
                {
                    //  msg.CC.Add(new MailAddress(currentCCAddress.Trim()));
                    string tempPath = Properties.Settings.Default["TempFile"].ToString();

                    string filePath = Path.Combine(tempPath, currentfiles);

                    using (System.IO.FileStream reader = System.IO.File.Create(filePath))
                    {
                        byte[] buffer = Convert.FromBase64String(mail.filecontent);
                        reader.Write(buffer, 0, buffer.Length);
                        reader.Dispose();
                    }

                    msg.Attachments.Add(new Attachment(filePath));
                }
            }
            // Include the reply to if not null
            if (mail.replyto != null)
            {
                msg.ReplyToList.Add(new MailAddress(mail.replyto));
            }
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");



            msg.From = new MailAddress("*****@*****.**");
            // mail.recipient("*****@*****.**");
            msg.Subject = mail.subject;
            msg.Body    = mail.body;
            try
            {
                SmtpServer.UseDefaultCredentials = false;;
                SmtpServer.Host           = "smtp.gmail.com";
                SmtpServer.Port           = 587;
                SmtpServer.Credentials    = new System.Net.NetworkCredential("*****@*****.**", "!Q2w3e4r");
                SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
                SmtpServer.EnableSsl      = true;
                SmtpServer.SendCompleted += SmtpServer_SendCompleted;

                SmtpServer.Send(msg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                msg.Dispose();
            }
        }