public async Task <IActionResult> CreateBulkLabel(CreateBulkLabelModel model) { if (model.IsNotValid()) { model.SetInputModelValues(); return(View(model)); } var labelListInfos = new List <LabelListInfo>(); var lines = model.BulkLabelData.Split('\n'); for (var i = 1; i < lines.Length; i++) { var values = lines[i].Split(','); if (values.Length != 3) { model.ErrorMessages.Add("file_has_more_columns_than_expected"); model.ErrorMessages.Add("error line : " + i); model.SetInputModelValues(); return(View(model)); } labelListInfos.Add(new LabelListInfo { LabelKey = values[0], LanguageIsoCode2 = values[1], Translation = values[2] }); } var request = new LabelCreateListRequest(CurrentUser.Id, model.OrganizationUid, model.ProjectUid, labelListInfos); var response = await _labelService.CreateLabelFromList(request); if (response.Status.IsNotSuccess) { model.MapMessages(response); model.SetInputModelValues(); return(View(model)); } var doneModel = new CreateBulkLabelDoneModel(); doneModel.MapMessages(response); doneModel.ProjectUid = model.ProjectUid; doneModel.ProjectName = model.ProjectName; doneModel.AddedLabelCount = response.AddedLabelCount; doneModel.CanNotAddedLabelCount = response.CanNotAddedLabelCount; doneModel.AddedLabelTranslationCount = response.AddedLabelTranslationCount; doneModel.CanNotAddedLabelTranslationCount = response.CanNotAddedLabelTranslationCount; doneModel.TotalRowsProcessed = lines.Length - 1; CurrentUser.IsActionSucceed = true; return(View("CreateBulkLabelDone", doneModel)); }
public static CreateBulkLabelModel MapCreateBulkLabelModel(ProjectDto project) { var model = new CreateBulkLabelModel(); model.OrganizationUid = project.OrganizationUid; model.ProjectUid = project.Uid; model.ProjectName = project.Name; model.SetInputModelValues(); return(model); }