//[Route("UpdateTemplate")] public async Task <IActionResult> UpdateTemplate([FromBody] ReviewTameplateForForm model) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", HttpContext.Session.GetString("SecurityToken")); string json = JsonConvert.SerializeObject(model); HttpResponseMessage msg = await client.PutAsync(siteName + "/api/Tameplate/UpdateTemplate", new StringContent(json, Encoding.UTF8, "application/json")); return(Ok()); } }
public IActionResult UpdateTemplate([FromBody] ReviewTameplateForForm model) { var review = context.ReviewTameplate.Where(x => x.Id == model.Id).Include(x => x.ReviewColumn).Include(x => x.HeaderRow).Include(x => x.ReviewRole).FirstOrDefault(); review.ReviewColumn = review.ReviewColumn.Select(x => { x.Deleted = true; return(x); }).ToList(); review.HeaderRow = review.HeaderRow.Select(x => { x.Deleted = true; return(x); }).ToList(); review.ReviewRole = review.ReviewRole.Select(x => { x.Deleted = true; return(x); }).ToList(); review.Name = model.Name; review.Description = model.Descritpion; foreach (var r in model.Roles) { ReviewRole role = review.ReviewRole.Where(x => x.Id == r.Id).FirstOrDefault(); if (role != null) { role.Name = r.Name; role.Deleted = false; } else { ReviewRole rl = new ReviewRole() { Name = r.Name }; review.ReviewRole.Add(rl); } } foreach (var c in model.Columns) { ReviewColumn column = review.ReviewColumn.Where(x => x.Id == c.Id).FirstOrDefault(); if (column != null) { var enums = context.ReviewColumnTypeEnum.Where(x => x.ReviewColumnId == column.Id).ToList(); context.ReviewColumnTypeEnum.RemoveRange(enums);//delete all enum and create new column.Type = c.Type; column.Name = c.ColumnName; column.Deleted = false; //var isHeaderMakeSense = context.ReviewColumn.Where(x => x.Id == column.Id).Include(x => x.HeaderRow).FirstOrDefault(); //bool sense = isHeaderMakeSense.HeaderRow. if (enums != null && c.Option != null) { foreach (string s in c.Option) { ReviewColumnTypeEnum t = new ReviewColumnTypeEnum() { Name = s }; column.ReviewColumnTypeEnum.Add(t); } } } else { ReviewColumn cl = new ReviewColumn() { Name = c.ColumnName, Type = c.Type }; if (c.Option != null) { foreach (string s in c.Option) { ReviewColumnTypeEnum t = new ReviewColumnTypeEnum() { Name = s }; cl.ReviewColumnTypeEnum.Add(t); } } review.ReviewColumn.Add(cl); } } foreach (var h in model.Header) { if (h.Id != null) { review.HeaderRow.Where(x => x.Id == h.Id).FirstOrDefault().Deleted = false; } else { var col = review.ReviewColumn.Where(x => x.Name == h.ColumnName).FirstOrDefault(); if (col != null) { HeaderRow header = new HeaderRow() { Function = h.Fcn, ReviewColumnId = col.Id, Name = h.Name, Parameter = h.Parameter, ReviewTameplateId = review.Id }; context.HeaderRow.Add(header); } else { HeaderRow header = new HeaderRow() { Name = h.Name, ReviewTameplateId = review.Id }; context.HeaderRow.Add(header); } } } context.SaveChanges(); return(Ok()); }
public ReviewTameplateForForm GetTameplate(int id) { ReviewTameplateForForm tameplate = new ReviewTameplateForForm(); var tmp = context.ReviewTameplate.Where(t => t.Id == id && t.Deleted != true).FirstOrDefault(); if (tmp != null) { tameplate.Id = tmp.Id; tameplate.Name = tmp.Name; tameplate.Descritpion = tmp.Description; var roles = context.ReviewRole.Where(r => r.ReviewTameplateId == id && r.Deleted != true).ToList(); List <Role> roleList = new List <Role>(); foreach (var r in roles) { Role role = new Role() { Id = r.Id, Name = r.Name }; roleList.Add(role); } tameplate.Roles = roleList; var header = context.HeaderRow.Where(h => h.ReviewTameplateId == tmp.Id && h.Deleted != true).ToList(); List <Header> headers = new List <Header>(); foreach (var head in header) { if (head.ReviewColumnId != null) { ReviewColumn c = context.ReviewColumn.Where(x => x.Id == head.ReviewColumnId).FirstOrDefault(); Header h = new Header() { Fcn = head.Function, Name = head.Name, Parameter = head.Parameter, ColumnName = c.Name, Id = head.Id, ColumnId = head.ReviewColumnId }; headers.Add(h); } else { Header h = new Header() { Fcn = head.Function, Name = head.Name, Parameter = head.Parameter, Id = head.Id }; headers.Add(h); } } tameplate.Header = headers; List <Column> columns = new List <Column>(); var cols = context.ReviewColumn.Where(c => c.ReviewTameplateId == tmp.Id && c.Deleted != true).ToList(); foreach (var c in cols) { Column col = new Column() { ColumnName = c.Name, Type = c.Type, Id = c.Id }; var opt = context.ReviewColumnTypeEnum.Where(o => o.ReviewColumnId == c.Id).ToList(); List <string> options = new List <string>(); foreach (var o in opt) { options.Add(o.Name); } col.Option = options; columns.Add(col); } tameplate.Columns = columns; return(tameplate); } return(null); }