public string ChangeStatus(UpdateOrderDto updateOrderDto)
        {
            string orderStatus = "";
            string retStatus   = "";

            try
            {
                var identity = (ClaimsPrincipal)Thread.CurrentPrincipal;
                var userId   = identity.Claims.Where(c => c.Type == ClaimTypes.Sid)
                               .Select(c => c.Value)
                               .SingleOrDefault();
                using (ORDR_MGMT_SYSEntities en = new ORDR_MGMT_SYSEntities())
                {
                    var updateOrder = en.USR_ORDERS.Where(x => x.ORD_ID == updateOrderDto.ORD_ID && x.ORD_LINE_NUM == updateOrderDto.LINE_NUM).SingleOrDefault();
                    updateOrder.ORDER_STATUS     = updateOrderDto.ORDER_STATUS;
                    updateOrder.LAST_MODIFIED_ON = DateTime.Now;
                    if (orderStatus == "Completed")
                    {
                        updateOrder.RECEIPT_DATE = DateTime.Now;
                    }
                    updateOrder.LAST_MODIFIED_BY = userId;
                    en.SaveChanges();
                }
                retStatus = "Updated Successfully";
            }
            catch (Exception ex)
            {
                retStatus = ex.InnerException.Message.ToString();
            }
            return(retStatus);
        }
        public string DeleteOrder(JObject orderId)
        {
            string resultStatus = "No Operation Performed";
            string _OrderID     = orderId["orderId"].Value <string>();

            try
            {
                using (ORDR_MGMT_SYSEntities en = new ORDR_MGMT_SYSEntities())
                {
                    List <USR_ORDERS> objs = en.USR_ORDERS.Where(x => x.ORD_ID == _OrderID).ToList <USR_ORDERS>();
                    if (objs.Count == 0)
                    {
                        throw new Exception("No Data Found! Order ID: " + _OrderID);
                    }

                    int _cnt = 0;
                    foreach (USR_ORDERS obj in objs)
                    {
                        var delObj = en.USR_ORDERS.Remove(obj);
                        if (delObj != null)
                        {
                            _cnt++;
                        }
                    }
                    resultStatus = "Deleted Successfully " + _cnt.ToString() + " out of " + objs.Count.ToString();
                    en.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                resultStatus = ex.Message;
            }
            return(resultStatus);
        }
        public string PostOrder(List <OrdersDto> orders)
        {
            ORDR_MGMT_SYSEntities entities = new ORDR_MGMT_SYSEntities();
            string status   = "";
            var    identity = (ClaimsPrincipal)Thread.CurrentPrincipal;

            var usr_id = identity.Claims.Where(c => c.Type == ClaimTypes.Sid)
                         .Select(c => c.Value)
                         .SingleOrDefault();
            var email = identity.Claims.Where(c => c.Type == ClaimTypes.Email)
                        .Select(c => c.Value)
                        .SingleOrDefault();

            System.Data.Entity.Core.Objects.ObjectParameter document_id = new System.Data.Entity.Core.Objects.ObjectParameter("RETURN_SERIES", typeof(string));
            entities.GenerateDocketSeries("ORDERS", DateTime.Now.Year.ToString(), document_id);
            if (document_id == null || document_id.Value.ToString() == "")
            {
                return("Docket series not found");
            }

            try
            {
                foreach (OrdersDto dto in orders)
                {
                    DateTime orderedDateTime;
                    DateTime.TryParseExact(dto.ORDERED_DATE, "dd-MM-yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out orderedDateTime);
                    entities.USR_ORDERS.Add(new USR_ORDERS
                    {
                        ORD_ID       = document_id.Value.ToString(),
                        PRD_ID       = dto.PRD_ID,
                        ORD_LINE_NUM = dto.LineNum,
                        PRD_QNTY     = dto.PRD_QNTY,
                        TAX_AMT      = dto.TAX_AMT,
                        NET_AMT      = dto.NET_AMT,
                        GROSS_AMT    = dto.GROSS_AMT,
                        DISC_AMT     = dto.DISC_AMT,
                        ORDRED_DATE  = orderedDateTime,
                        ORDER_STATUS = dto.ORDER_STATUS,
                        CREATED_BY   = usr_id,
                        CUSTOMER_ID  = usr_id,
                        CREATED_ON   = DateTime.Now
                    });
                }
                entities.SaveChanges();
                status = "Inserted Successfully. ";

                EmailSending sending = new EmailSending();
                status += sending.SendMail(email, "Your has been placed", usr_id);
            }
            catch (Exception ex)
            {
                status = ex.Message;
            }

            return(status);
        }