示例#1
0
        private bool SaveUniqueCouponInstance(int couponId, string code, out string error)
        {
            try
            {
                var entities = CouponInstanceRepository.GetMany(x => x.CouponId == couponId && x.CouponCode == code).ToList();

                if (!entities.Any())
                {
                    CouponInstanceRepository.Add((new CouponDTO
                    {
                        CouponId = couponId,
                        CouponCode = code,
                        UsageLimit = 1
                    }).CourseCouponDto2CouponInstanceEntity(code));
                }
                else
                {
                    error = "already exists";
                    return(false);
                }

                return(CouponInstanceRepository.UnitOfWork.CommitAndRefreshChanges(out error));
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                return(false);
            }
        }
示例#2
0
        private bool SaveCouponInstance(CouponDTO dto, out string error)
        {
            try
            {
                var entities = CouponInstanceRepository.GetMany(x => x.CouponId == dto.CouponId).ToList();

                if (!entities.Any())
                {
                    CouponInstanceRepository.Add(dto.CourseCouponDto2CouponInstanceEntity());
                }
                else
                {
                    if (entities.Count().Equals(1))
                    {
                        var entity = entities[0];
                        entity.UpdateCouponInstanceEntity(dto);
                    }
                    //else
                    //{
                    //TODO ask for logic
                    //}
                }

                return(CouponInstanceRepository.UnitOfWork.CommitAndRefreshChanges(out error));
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                return(false);
            }
        }