Ejemplo n.º 1
0
        public void ServiceOutsideDetailSave(ServiceOutsideDTO serviceOutsideDTO, ServiceOutside serviceOutside)
        {
            var listNewServiceOutsideDetailId = new List <int>();

            foreach (var serviceOutsideDetailDTO in serviceOutsideDTO.listServiceOutsideDetailDTO)
            {
                ServiceOutsideDetail serviceOutsideDetail = null;
                var unitPrice = 0.0;
                try
                {
                    unitPrice = Double.Parse(serviceOutsideDetailDTO.unitPrice);
                }
                catch { }
                var quantity = 0;
                try
                {
                    quantity = Convert.ToInt32(serviceOutsideDetailDTO.quantity);
                }
                catch { }
                var totalPrice = 0.0;
                try
                {
                    totalPrice = Double.Parse(serviceOutsideDetailDTO.totalPrice);
                }
                catch { }
                if (serviceOutsideDetailDTO.id <= 0)
                {
                    serviceOutsideDetail = new ServiceOutsideDetail();
                }
                else if (serviceOutsideDetailDTO.id > 0)
                {
                    serviceOutsideDetail = BookingViewingBLL.ServiceOutsideDetailGetById(serviceOutsideDetailDTO.id);
                }
                serviceOutsideDetail.Name           = serviceOutsideDetailDTO.name;
                serviceOutsideDetail.UnitPrice      = unitPrice;
                serviceOutsideDetail.Quantity       = quantity;
                serviceOutside.TotalPrice           = totalPrice;
                serviceOutsideDetail.ServiceOutside = serviceOutside;
                BookingViewingBLL.ServiceOutsideDetailSaveOrUpdate(serviceOutsideDetail);
                listNewServiceOutsideDetailId.Add(serviceOutsideDetail.Id);
                var listServiceOutsideDetail             = BookingViewingBLL.ServiceOutsideDetailGetAllByServiceOutsideId(serviceOutside.Id);
                var listIdOfServiceOutsideDetail         = listServiceOutsideDetail.Select(x => x.Id).ToList();
                var listIdOfServiceOutsideDetailDTO      = serviceOutsideDTO.listServiceOutsideDetailDTO.Where(x => x.id > 0).Select(x => x.id).ToList();
                var listServiceOutsideDetailIdNeedRemove = listIdOfServiceOutsideDetail.Except(listIdOfServiceOutsideDetailDTO).Except(listNewServiceOutsideDetailId);
                foreach (var serviceOutsideDetailIdNeedRemove in listServiceOutsideDetailIdNeedRemove)
                {
                    var serviceOutsideDetailNeedRemove = BookingViewingBLL.ServiceOutsideDetailGetById(serviceOutsideDetailIdNeedRemove);
                    BookingViewingBLL.ServiceOutsideDetailDelete(serviceOutsideDetailNeedRemove);
                }
                Dispose();
            }
        }
Ejemplo n.º 2
0
        public string ServiceOutsideGetAllByBookingId(int restaurantBookingId)
        {
            var listServiceOutside    = BookingViewingBLL.ServiceOutsideGetAllByBookingId(restaurantBookingId);
            var listServiceOutsideDTO = new List <ServiceOutsideDTO>();

            foreach (var serviceOutside in listServiceOutside)
            {
                var serviceOutsideDTO = new ServiceOutsideDTO()
                {
                    id                  = serviceOutside.Id,
                    service             = serviceOutside.Service,
                    unitPrice           = serviceOutside.UnitPrice.ToString("#,##0.##"),
                    quantity            = serviceOutside.Quantity,
                    totalPrice          = serviceOutside.TotalPrice.ToString("#,##0.##"),
                    restaurantBookingId = serviceOutside.RestaurantBooking.Id,
                    vat                 = serviceOutside.VAT,
                };
                listServiceOutsideDTO.Add(serviceOutsideDTO);
            }
            Dispose();
            return(JsonConvert.SerializeObject(listServiceOutsideDTO));
        }