Example #1
0
        public async Task <bool> UpdateTemplateAsync(UpdateTextTemplateRequest templates)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    _db.ProductTextTemplates.RemoveRange(_db.ProductTextTemplates.Where(c => c.SegmentId == templates.SegmentId));
                    await _db.SaveChangesAsync();

                    await _db.ProductTextTemplates.AddRangeAsync(templates.Templates.Select(c => new ProductTextTemplate()
                    {
                        SegmentId = templates.SegmentId, Template = c.Body, MinPrice = c.MinPrice, MaxPrice = c.MaxPrice
                    }));

                    await _db.SaveChangesAsync();

                    transaction.Commit();
                    return(true);
                }
                catch
                {
                    transaction.Rollback();
                    return(false);
                }
            }
        }
Example #2
0
        public async Task <EmptyResponse> Update([FromBody] UpdateTextTemplateRequest request)
        {
            var result = await _textTemplateManager.UpdateTemplateAsync(request);

            return(new EmptyResponse()
            {
                Valid = result
            });
        }