Beispiel #1
0
        public ActionResult FinishVisit(int ActId, string resume, IEnumerable <string> products, bool?double_visit)
        {
            var act = ActivityRep.Get(ActId);

            act.act_state_id  = 2;
            act.fact_date     = act.plan_date;
            act.goal_achieved = resume;
            act.double_visit  = double_visit;
            act.edited_date   = DateTime.UtcNow;
            act.edited_by     = User.Identity.Name;
            ActivityRep.AddOrUpdate(act);

            if (products != null)
            {
                foreach (var item in products)
                {
                    var ActivityProd = new ActivityProduct()
                    {
                        prod_id = Convert.ToInt32(item), act_id = act.id
                    };
                    ActivityProductRep.AddOrUpdate(ActivityProd);
                }
            }
            return(new EmptyResult());
        }
Beispiel #2
0
        public ActionResult PostJsonActivityUpdate(int?prodid = null, int?actid = null)
        {
            if (prodid == null || actid == null)
            {
                return(Json(new
                {
                    Status = false,
                    Message = "未選擇活動,資料未變更",
                }));
            }
            try
            {
                if (db.ActivityProducts.Any(A => A.ProductID == prodid && A.ActivityID != actid))
                {
                    var _ap = db.ActivityProducts.Where(W => W.ProductID == prodid && W.ActivityID != actid).ToList();

                    foreach (var _data in _ap)
                    {
                        var _apt = db.ActivityProducts.Find(_data.ActivityDetailID);

                        db.ActivityProducts.Remove(_apt);
                    }
                }

                //Create
                if (db.ActivityProducts.Any(A => A.ProductID == prodid && A.ActivityID == actid))
                {
                    ActivityProduct _ap = new ActivityProduct();

                    _ap.ActivityID = (int)actid;
                    _ap.ProductID  = (int)prodid;
                    _ap.CreateDate = DateTime.Now;

                    db.ActivityProducts.Add(_ap);
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Status = false,
                    Message = ex.ToString(),
                }));
            }

            return(Json(new
            {
                Status = true,
                Message = "活動設定成功!",
            }));
        }
Beispiel #3
0
        public ActionResult UpdateActivity(int prodid = 0, int activityid = 0)
        {
            if (prodid == 0 || activityid == 0)
            {
                return(Json(new
                {
                    Status = false,
                    Message = "沒有選擇活動, 無法更改!",
                }));
            }
            try
            {
                //將不該有的Activity中的Product刪除
                if (db.ActivityProducts.Any(x => x.ProductID == prodid && x.ActivityID != activityid))
                {
                    List <ActivityProduct> aplist = db.ActivityProducts.Where(x => x.ProductID == prodid && x.ActivityID != activityid).ToList();

                    foreach (var item in aplist)
                    {
                        var apt = db.ActivityProducts.Find(item.ActivityDetailID);
                        db.ActivityProducts.Remove(apt);
                    }
                }

                //若不存在,則須在Activity中增加Product
                if (!db.ActivityProducts.Any(x => x.ProductID == prodid && x.ActivityID == activityid))
                {
                    ActivityProduct ap = new ActivityProduct();
                    ap.ActivityID = activityid;
                    ap.ProductID  = prodid;
                    ap.CreateDate = DateTime.Now;
                    db.ActivityProducts.Add(ap);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Status = false,
                    Message = ex.ToString(),
                }));
            }

            return(Json(new
            {
                Status = true,
            }));
        }
Beispiel #4
0
        public async Task AddProductsAsync(Guid activityId, IEnumerable <Guid> productIds, string creator)
        {
            var activity = await _db.Activities.SingleOrDefaultAsync(a => a.Id == activityId);

            var activityProducts = await _db.ActivityProducts.Include(ap => ap.Product).Where(ap => ap.Activity.Id == activityId).ToListAsync();

            if (activity != null)
            {
                var now      = DateTime.Now;
                var products = await _db.Products.Where(p => productIds.Contains(p.Id)).ToListAsync();

                foreach (var p in products)
                {
                    if (activityProducts.Any(ap => ap.Product.Id == p.Id))
                    {
                        continue;
                    }

                    var activityProduct = new ActivityProduct
                    {
                        Id            = Guid.NewGuid(),
                        Activity      = activity,
                        Product       = p,
                        PointsPayment = p.PointsPayment,
                        SelfPayment   = p.SelfPayment
                    };
                    activityProduct.UpdatedTime = activityProduct.CreatedTime = now;
                    activityProduct.UpdatedBy   = activityProduct.CreatedBy = creator;

                    _db.ActivityProducts.Add(activityProduct);
                }

                if (products.Count > 0)
                {
                    activity.UpdatedTime = now;
                    activity.UpdatedBy   = creator;
                }

                await _db.SaveChangesAsync();
            }
        }
        private string CheckPIDSamePriceInOtherActivity(ActivityProduct product)
        {
            var conn = ConfigurationManager.ConnectionStrings["Gungnir"].ConnectionString;

            if (SecurityHelp.IsBase64Formatted(conn))
            {
                conn = SecurityHelp.DecryptAES(conn);
            }
            using (var dbHelper = new Tuhu.Component.Common.SqlDbHelper(conn))
            {
                var cmd = new SqlCommand(@"SELECT	FS.ActivityID,FSP.Price,FSP.PID
                                            FROM	Activity..tbl_FlashSale AS FS WITH ( NOLOCK )
                                            JOIN	Activity..tbl_FlashSaleProducts AS FSP WITH ( NOLOCK )
		                                            ON FSP.ActivityID = FS.ActivityID
                                            WHERE	FS.EndDateTime > GETDATE()
		                                            AND FSP.PID = @PID
		                                            AND FSP.Price <> @Price
		                                            AND FS.ActivityID<>@ActivityID
		                                            AND ActiveType IN ( 0, 1 )"        );
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@PID", product.PID);
                cmd.Parameters.AddWithValue("@Price", product.Price);
                cmd.Parameters.AddWithValue("@ActivityID", product.ActivityID);
                var dt = dbHelper.ExecuteDataTable(cmd);
                if (dt == null || dt.Rows.Count == 0)
                {
                    return(null);
                }
                var wrongMsg = "";
                foreach (DataRow item in dt.Rows)
                {
                    wrongMsg += "PID:" + item["PID"].ToString() + "&nbsp;&nbsp;&nbsp;&nbsp;活动ID:" + item["ActivityID"].ToString() + "&nbsp;&nbsp;&nbsp;&nbsp;价格:" + Convert.ToDouble(item["Price"]).ToString("C") + "<br/>";
                }
                return(wrongMsg);
            }
        }
Beispiel #6
0
 public static void Save(ActivityProduct activity, BinaryWriter save)
 {
     activity.Save(save);
 }