Example #1
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id      = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    Goods good = context.Goods.Find(this.GoodId);

                    if (good != null)
                    {
                        UserClicks model = (
                            from uc in context.UserClicks
                            where uc.PromoterId.Equals(this.PromoterId) &&
                            uc.CustomerId.Equals(this.CustomerId) &&
                            uc.GoodId.Equals(this.GoodId)
                            select uc
                            ).FirstOrDefault();

                        if (model == null)
                        {
                            model = new UserClicks
                            {
                                Id         = this.Id,
                                PromoterId = this.PromoterId,
                                CustomerId = this.CustomerId,
                                GoodId     = this.GoodId,
                                AddDate    = this.AddDate
                            };

                            good.Clicks++;
                            context.UserClicks.Add(model);
                            context.SaveChanges();
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    Goods good = context.Goods.Find(this.GoodId);

                    if (good != null)
                    {
                        UserClicks model = (
                            from uc in context.UserClicks
                            where uc.PromoterId.Equals(this.PromoterId)
                               && uc.CustomerId.Equals(this.CustomerId)
                               && uc.GoodId.Equals(this.GoodId)
                            select uc
                        ).FirstOrDefault();

                        if (model == null)
                        {
                            model = new UserClicks
                            {
                                Id = this.Id,
                                PromoterId = this.PromoterId,
                                CustomerId = this.CustomerId,
                                GoodId = this.GoodId,
                                AddDate = this.AddDate
                            };

                            good.Clicks++;
                            context.UserClicks.Add(model);
                            context.SaveChanges();
                        }
                    }
                }

                return true;
            }

            return false;
        }