Пример #1
0
        public int InsertDoorsxOrder(DoorxOrder pDoorsxOrder)
        {
            try
            {
                lnDecimals      deci     = new lnDecimals();
                List <Decimals> listDeci = deci.GetAllDecimals();
                lnDoorsPrices   dp       = new lnDoorsPrices();
                lnDoorsxUser    DU       = new lnDoorsxUser();
                lnOrder         _LNOrder = new lnOrder();
                Order           item     = null;
                DoorsxUser      DoorUser = null;
                if (pDoorsxOrder.TEMP == true)
                {
                    DoorUser      = DU.GetTEMPdxuById(pDoorsxOrder.DoorxUser.Id);
                    DoorUser.TEMP = true;
                    item          = _LNOrder.GetTEMPorderById(DoorUser.Order.Id);
                    item.TEMP     = true;
                }
                else
                {
                    item     = _LNOrder.GetOrderByUser(pDoorsxOrder.User.Id).Where(x => x.Status.Id == 4).FirstOrDefault();
                    DoorUser = DU.GetAllDoorsxUser().Where(x => x.Order.Id == item.Id).FirstOrDefault();
                }
                pDoorsxOrder.DoorxUser = DoorUser;
                int Rail = 1;
                if (DoorUser.TopRail.Id == 3 || DoorUser.BottomRail.Id == 3 || DoorUser.DoorStyle.Id == 1009 || DoorUser.DoorStyle.Id == 1008)
                {
                    Rail = 2;
                }
                int panel = 5;
                if (DoorUser.Panel.Id == 2)
                {
                    panel = DoorUser.Panel.Id;
                }
                if (DoorUser.DoorStyle.Id == 1010)
                {
                    panel = 2;
                }
                lnUser _LNUser = new lnUser();
                User   u       = new User();
                u = _LNUser.GetUserById(pDoorsxOrder.User.Id);
                DoorsPrices DoorPrice = dp.GetDoorsPricesById(0, panel, DoorUser.Material.Id, Rail);
                decimal     deciW     = listDeci.Where(x => x.Id == pDoorsxOrder.DecimalsWidth.Id).FirstOrDefault().Value;
                decimal     deciH     = listDeci.Where(x => x.Id == pDoorsxOrder.DecimalsHeight.Id).FirstOrDefault().Value;
                decimal     Width     = pDoorsxOrder.Width + deciW;
                decimal     Height    = pDoorsxOrder.Height + deciH;
                decimal     a         = 1;
                decimal     b         = 1;
                decimal     aux       = 1;
                while (!(aux == deciW))
                {
                    aux = a / b;
                    if (aux < deciW)
                    {
                        a++;
                    }
                    else if (aux > deciW)
                    {
                        a--;
                        b++;
                    }
                }
                string fracc = a.ToString() + "/" + b.ToString();
                pDoorsxOrder.User = u;
                decimal result = (((((Width * Height) / 12m) / 12m) - 1.5m) * DoorPrice.AdditionalSFPrice) + DoorPrice.BasePrice;
                if ((DoorUser.DoorStyle.Id == 1010))
                {
                    result = result / 100m * 80m;
                }
                if (result < DoorPrice.BasePrice)
                {
                    result = DoorPrice.BasePrice * 2;
                    if (pDoorsxOrder.User.Descuento > 0)
                    {
                        decimal des = decimal.Parse(pDoorsxOrder.User.Descuento.ToString()) / 100m;
                        result = result - (des * result);
                    }
                    if (pDoorsxOrder.Descuento > 0)
                    {
                        decimal des = decimal.Parse(pDoorsxOrder.Descuento.ToString()) / 100m;
                        pDoorsxOrder.TotalDescuento = result * des;
                        result = result - (des * result);
                    }
                    pDoorsxOrder.ItemCost = result;
                    pDoorsxOrder.SubTotal = result * pDoorsxOrder.Quantity;
                }
                else
                {
                    result = result * 2;
                    if (pDoorsxOrder.User.Descuento > 0)
                    {
                        decimal des = decimal.Parse(pDoorsxOrder.User.Descuento.ToString()) / 100m;
                        pDoorsxOrder.TotalDescuento = result * des;
                        result = result - (des * result);
                    }
                    if (pDoorsxOrder.Descuento > 0)
                    {
                        decimal des = decimal.Parse(pDoorsxOrder.Descuento.ToString()) / 100m;
                        pDoorsxOrder.TotalDescuento = result * des;
                        result = result - (des * result);
                    }
                    pDoorsxOrder.ItemCost = result;
                    pDoorsxOrder.SubTotal = result * pDoorsxOrder.Quantity;
                }

                if (DoorUser.isDrill == false)
                {
                    pDoorsxOrder.HingeDirection.Id = 3;
                    pDoorsxOrder.HingePositions.Id = 2;
                }
                else
                {
                    pDoorsxOrder.HingeDirection.Id = pDoorsxOrder.HingeDirection.Id;
                    pDoorsxOrder.HingePositions.Id = 2;
                }
                pDoorsxOrder.CreationDate     = DateTime.Now;
                pDoorsxOrder.ModificationDate = DateTime.Now;
                pDoorsxOrder.CreatorUser      = pDoorsxOrder.User.Id;
                pDoorsxOrder.ModificationUser = pDoorsxOrder.User.Id;
                pDoorsxOrder.ProfilePicture   = DU.BuscarProfilePicture(DoorUser.OutsideEdgeProfile.Id, DoorUser.InsideEdgeProfile.Id, DoorUser.Panel.Id);
                pDoorsxOrder.Picture          = DU.BuscarDoorPicture(pDoorsxOrder);
                int retorno = _AD.InsertDoorsxOrder(pDoorsxOrder);
                item.SubTotal = item.SubTotal + pDoorsxOrder.SubTotal;
                item.Tax      = 0.0825m * item.SubTotal;
                item.Total    = item.Tax + item.SubTotal;
                item.Quantity = item.Quantity + pDoorsxOrder.Quantity;
                _LNOrder.UpdateOrder(item);
                return(retorno);
            }
            catch (Exception ex)
            {
                throw;
            }
        }