public IHttpActionResult CreateNewTemplate([FromUri] string templateName, [FromUri] string customer, [FromUri] string timeUnit, [FromUri] string currency)
        {
            var newTemplate = new ChargeTemplate {
                TemplateName = templateName,
                Customer     = customer,
                TimeUnit     = timeUnit,
                Currency     = currency
            };

            _context.ChargeTemplates.Add(newTemplate);
            _context.SaveChanges();

            var sample = _context.ChargeTemplates
                         .OrderByDescending(x => x.Id)
                         .First();

            return(Created(Request.RequestUri + "/" + sample.Id, Mapper.Map <ChargeTemplate, ChargeTemplateDto>(sample)));
        }
Exemplo n.º 2
0
        public IHttpActionResult CreateNewChargeMethod([FromUri] int templateId, [FromUri] int from, [FromUri] int to, [FromUri] double fee)
        {
            int duration           = to - from + 1;
            var chargeTemplateInDb = _context.ChargeTemplates.Find(templateId);

            //try
            //{
            //    if (period.Split('-').Count() > 1)
            //    {
            //        weeks = int.Parse(period.Split('-')[1]) - int.Parse(period.Split('-')[0]);

            //    }
            //    else
            //    {
            //        weeks = int.Parse(period);
            //    }
            //}
            //catch(Exception e)
            //{
            //    throw new Exception("Period is invalid.");
            //}

            var newMethod = new ChargeMethod
            {
                Fee            = fee,
                From           = from,
                To             = to,
                Duration       = duration,
                ChargeTemplate = chargeTemplateInDb,
                TimeUnit       = chargeTemplateInDb.TimeUnit,
                Currency       = chargeTemplateInDb.Currency
            };

            _context.ChargeMethods.Add(newMethod);
            _context.SaveChanges();

            var sample = _context.ChargeMethods.OrderByDescending(x => x.Id).First();

            return(Created(Request.RequestUri + "/" + sample.Id, Mapper.Map <ChargeMethod, ChargeMethodDto>(sample)));
        }