예제 #1
0
        public MEDItemDto MEDItemsById(long id)
        {
            MEDItemDto ItemDto = new MEDItemDto();

            using (EAharaDB context = new EAharaDB())
            {
                var acctype = context.MEDItems.FirstOrDefault(x => x.IsActive == true && x.Id == id);

                if (acctype != null)
                {
                    ItemDto.Id               = acctype.Id;
                    ItemDto.MEDOfferId       = acctype.MEDOfferId;
                    ItemDto.Name             = acctype.Name;
                    ItemDto.MEDSubCategoryId = acctype.MEDSubCategoryId;
                    ItemDto.Image1           = acctype.Image1;
                    ItemDto.OfferPrice       = acctype.OfferPrice;
                    ItemDto.Price            = acctype.Price;
                    ItemDto.Image2           = acctype.Image2;
                    ItemDto.Description      = acctype.Description;
                    ItemDto.Tagline          = acctype.Tagline;
                    ItemDto.Image3           = acctype.Image3;
                    ItemDto.IsAvailable      = acctype.IsAvailable;
                    ItemDto.Image4           = acctype.Image4;
                    ItemDto.IsActive         = true;
                    ItemDto.MEDCategoryId    = acctype.MEDCategoryId;
                    ItemDto.MEDBrandId       = acctype.MEDBrandId;
                    ItemDto.MEDShopId        = acctype.MEDShopId;
                    ItemDto.MEDBrand         = new MEDBrandDto
                    {
                        Id   = acctype.MEDBrand != null ? acctype.MEDBrand.Id : 0,
                        Name = acctype.MEDBrand != null ? acctype.MEDBrand.Name : "",
                    };
                    ItemDto.MEDShop = new MEDShopDto
                    {
                        Id   = acctype.MEDShop != null ? acctype.MEDShop.Id : 0,
                        Name = acctype.MEDShop != null ? acctype.MEDShop.Name : "",
                    };

                    ItemDto.MEDOffer = new MEDOfferDto
                    {
                        Id         = acctype.MEDOffer != null ?  acctype.MEDOffer.Id :0,
                        Image      = acctype.MEDOffer != null ?  acctype.MEDOffer.Image : "",
                        Title      = acctype.MEDOffer != null ? acctype.MEDOffer.Title : "",
                        Percentage = acctype.MEDOffer != null ?  acctype.MEDOffer.Percentage : 0,
                    };

                    ItemDto.MEDSubCategory = new MEDSubCategoryDto
                    {
                        Id   = acctype.MEDSubCategory.Id,
                        Name = acctype.MEDSubCategory.Name,
                    };
                }
            }
            return(ItemDto);
        }
예제 #2
0
        public MEDItemDto GetMEDItemInCart(long id)
        {
            MEDItemDto ItemDto = new MEDItemDto();

            using (EAharaDB context = new EAharaDB())
            {
                var acctype = context.MEDItems.FirstOrDefault(x => x.IsActive == true && x.Id == id);

                if (acctype != null)
                {
                    ItemDto.Id               = acctype.Id;
                    ItemDto.MEDOfferId       = acctype.MEDOfferId;
                    ItemDto.Name             = acctype.Name;
                    ItemDto.MEDSubCategoryId = acctype.MEDSubCategoryId;
                    ItemDto.OfferPrice       = acctype.OfferPrice;
                    ItemDto.Price            = acctype.Price;
                    ItemDto.Description      = acctype.Description;
                    ItemDto.Tagline          = acctype.Tagline;
                    ItemDto.IsAvailable      = acctype.IsAvailable;
                    ItemDto.IsActive         = true;
                }
            }
            return(ItemDto);
        }
예제 #3
0
        public bool AddMEDItems(MEDItemDto itemDto)
        {
            if (itemDto != null)
            {
                using (EAharaDB context = new EAharaDB())
                {
                    if (itemDto.Id > 0)
                    {
                        var data = context.MEDItems.FirstOrDefault(x => x.Id == itemDto.Id);
                        if (data != null)
                        {
                            data.Name             = itemDto.Name;
                            data.Tagline          = itemDto.Tagline;
                            data.Price            = itemDto.Price;
                            data.MEDOfferId       = itemDto.MEDOfferId;
                            data.MEDSubCategoryId = itemDto.MEDSubCategoryId;
                            data.IsAvailable      = itemDto.IsAvailable;
                            data.OfferPrice       = itemDto.Price;
                            data.Description      = itemDto.Description;
                            data.MEDCategoryId    = itemDto.MEDCategoryId;
                            data.MEDBrandId       = itemDto.MEDBrandId;
                            data.MEDShopId        = itemDto.MEDShopId;
                            data.Bookings         = itemDto.Bookings;
                            if (data.MEDOfferId > 0)
                            {
                                var offer = context.MEDOffers.FirstOrDefault(x => x.Id == data.MEDOfferId);

                                if (offer.IsPercentage)
                                {
                                    data.OfferPrice = data.OfferPrice - (data.OfferPrice * offer.Percentage) / 100;
                                }
                                else
                                {
                                    data.OfferPrice = data.OfferPrice - offer.Percentage;
                                }
                            }

                            context.Entry(data).Property(x => x.Name).IsModified             = true;
                            context.Entry(data).Property(x => x.MEDShopId).IsModified        = true;
                            context.Entry(data).Property(x => x.Tagline).IsModified          = true;
                            context.Entry(data).Property(x => x.Price).IsModified            = true;
                            context.Entry(data).Property(x => x.MEDOfferId).IsModified       = true;
                            context.Entry(data).Property(x => x.MEDSubCategoryId).IsModified = true;
                            context.Entry(data).Property(x => x.IsAvailable).IsModified      = true;
                            context.Entry(data).Property(x => x.OfferPrice).IsModified       = true;
                            context.Entry(data).Property(x => x.Description).IsModified      = true;
                            context.Entry(data).Property(x => x.MEDCategoryId).IsModified    = true;
                            context.Entry(data).Property(x => x.MEDBrandId).IsModified       = true;
                            context.Entry(data).Property(x => x.Bookings).IsModified         = true;

                            if (itemDto.Image1 != null && itemDto.Image1 != "" && data.Image1 != itemDto.Image1 && !itemDto.Image1.Contains("localhost") && !itemDto.Image1.Contains("http"))
                            {
                                data.Image1 = storeImage(itemDto.Image1);
                                context.Entry(data).Property(x => x.Image1).IsModified = true;
                            }

                            if (itemDto.Image2 != null && itemDto.Image2 != "" && data.Image2 != itemDto.Image2 && !itemDto.Image2.Contains("localhost:") && !itemDto.Image1.Contains("http"))
                            {
                                data.Image2 = storeImage(itemDto.Image2);
                                context.Entry(data).Property(x => x.Image2).IsModified = true;
                            }

                            if (itemDto.Image3 != null && itemDto.Image3 != "" && data.Image3 != itemDto.Image3 && !itemDto.Image3.Contains("localhost:") && !itemDto.Image1.Contains("http"))
                            {
                                data.Image3 = storeImage(itemDto.Image3);
                                context.Entry(data).Property(x => x.Image3).IsModified = true;
                            }
                            if (itemDto.Image4 != null && itemDto.Image4 != "" && data.Image4 != itemDto.Image4 && !itemDto.Image4.Contains("localhost:") && !itemDto.Image1.Contains("http"))
                            {
                                data.Image4 = storeImage(itemDto.Image4);
                                context.Entry(data).Property(x => x.Image4).IsModified = true;
                            }
                            context.SaveChanges();
                            return(true);
                        }
                        return(false);
                    }
                    else
                    {
                        MEDItem item = new MEDItem();

                        item.Name             = itemDto.Name;
                        item.Tagline          = itemDto.Tagline;
                        item.Price            = itemDto.Price;
                        item.MEDOfferId       = itemDto.MEDOfferId;
                        item.MEDSubCategoryId = itemDto.MEDSubCategoryId;
                        item.IsAvailable      = itemDto.IsAvailable;
                        item.MEDBrandId       = itemDto.MEDBrandId;
                        item.OfferPrice       = itemDto.Price;
                        item.Description      = itemDto.Description;
                        item.MEDCategoryId    = itemDto.MEDCategoryId;
                        item.MEDShopId        = itemDto.MEDShopId;
                        item.IsActive         = true;

                        if (item.MEDOfferId > 0)
                        {
                            var offer = context.MEDOffers.FirstOrDefault(x => x.Id == item.MEDOfferId);

                            if (offer.IsPercentage)
                            {
                                item.OfferPrice = item.OfferPrice - (item.OfferPrice * offer.Percentage) / 100;
                            }
                            else
                            {
                                item.OfferPrice = item.OfferPrice - offer.Percentage;
                            }
                        }

                        if (itemDto.Image1 != null && itemDto.Image1 != "")
                        {
                            item.Image1 = storeImage(itemDto.Image1);
                        }
                        if (itemDto.Image2 != null && itemDto.Image2 != "")
                        {
                            item.Image2 = storeImage(itemDto.Image2);
                        }

                        if (itemDto.Image3 != null && itemDto.Image3 != "")
                        {
                            item.Image3 = storeImage(itemDto.Image3);
                        }

                        if (itemDto.Image4 != null && itemDto.Image4 != "")
                        {
                            item.Image4 = storeImage(itemDto.Image4);
                        }
                        context.MEDItems.Add(item);
                        context.SaveChanges();
                        return(true);
                    }
                }
            }
            return(false);
        }