Пример #1
0
        public static int CopyProgram(int id, string loggedOnUser)
        {
            using (CustomClearviewEntities ctx = new CustomClearviewEntities())
            {
                RateRepository repo    = new RateRepository(ctx);
                Program        current = repo.Find(r => r.ProgramId == id, type => type.ProgramVendors);

                Program copy = new Program
                {
                    AccountNumberFixedLength = current.AccountNumberFixedLength,
                    AccountNumberLength      = current.AccountNumberLength,
                    AccountNumberTypeId      = current.AccountNumberTypeId,
                    BrandId = current.BrandId,
                    CancellationVerbiage        = current.CancellationVerbiage,
                    CancellationVerbiageSpanish = current.CancellationVerbiageSpanish,
                    EffectiveEndDate            = current.EffectiveEndDate,
                    EffectiveStartDate          = current.EffectiveStartDate,
                    Etf                 = current.Etf,
                    Hefpa               = current.Hefpa,
                    Market              = current.Market,
                    MeterNumber         = current.MeterNumber,
                    MeterNumberLength   = current.MeterNumberLength,
                    Msf                 = current.Msf,
                    PremiseTypeId       = current.PremiseTypeId,
                    ProgramCode         = current.ProgramCode + " - COPY",
                    ProgramName         = current.ProgramName + " - COPY",
                    ProgramDescription  = current.ProgramDescription + " - COPY",
                    PromotionalCode     = current.PromotionalCode,
                    Rate                = current.Rate,
                    RateVerbiage        = current.RateVerbiage,
                    RateVerbiageSpanish = current.RateVerbiageSpanish,
                    RescindBy           = current.RescindBy,
                    SalesChannel        = current.SalesChannel,
                    State               = current.State,
                    Term                = current.Term,
                    UnitOfMeasureId     = current.UnitOfMeasureId,
                    UtilityId           = current.UtilityId,
                    UtilityTypeId       = current.UtilityTypeId,
                    UpdatedBy           = loggedOnUser,
                    UpdatedDateTime     = DateTime.Now,
                    ServiceReference    = current.ServiceReference,
                    CreditCheck         = current.CreditCheck
                };

                foreach (ProgramVendor pv in current.ProgramVendors)
                {
                    copy.ProgramVendors.Add(new ProgramVendor
                    {
                        VendorId        = pv.VendorId,
                        CreatedBy       = "test",
                        CreatedDateTime = DateTime.Now
                    });
                }

                repo.Create(copy);
                ctx.SaveChanges();

                return(copy.ProgramId);
            }
        }
Пример #2
0
        public static int CreateRate(Program program)
        {
            if (program == null)
            {
                throw new System.ArgumentNullException()
                      {
                          Source = "program"
                      };
            }

            using (CustomClearviewEntities ctx = new CustomClearviewEntities())
            {
                RateRepository repo = new RateRepository(ctx);
                repo.Create(program);
                ctx.SaveChanges();
            }

            return(program.ProgramId);
        }
Пример #3
0
        public async Task <ActionResult> Create(RateCreateDto createDto)
        {
            var user = await _GetAuthUser();

            // should never happens, only if [Authorize] is removed
            if (user == null)
            {
                return(Unauthorized());
            }

            var rate = _mapper.Map <RateEntity>(createDto);

            rate.UserId = user.Id; // rate is based on current "logged" user

            try
            {
                // not need to wrap in transactions BoardGame rates can be always recalculate from Rates
                await _rateRepository.Create(rate);

                var boardGame = await _boardGameRepository.GetById(rate.BoardGameId);

                await _boardGameRepository.AddRate(boardGame, rate.Vote);

                return(Ok());
            }
            catch (Exception exception)
            {
                if (exception is RecordNotFoundException)
                {
                    return(BadRequest(exception.Message));
                }

                if (exception is UniqueException)
                {
                    return(Conflict(exception.Message));
                }

                throw;
            }
        }
Пример #4
0
 public void CreateItem(Rate rate)
 {
     _rateService.Create(rate);
 }