Esempio n. 1
0
        public async Task <IActionResult> UploadDepartmentExcel(DepartmentCollectionModel model)
        {
            var depts    = model.depts;
            var entities = depts.Select(u => u.ToEntity());
            var rs       = new List <DepartmentErrorableModel>();

            foreach (var item in entities)
            {
                try
                {
                    await _coreRep.UpdateOrAddDepartmentByCode(item, await getCurrentUser());

                    if (item.ParentId != null)
                    {
                        item.Parent = await _coreRep.GetDepartmentById(item.ParentId ?? 0);
                    }
                    var irs = new DepartmentErrorableModel(item);
                    rs.Add(irs);
                }
                catch (Exception e)
                {
                    var irs = new DepartmentErrorableModel(item);
                    irs.messages.Add(MessageModel.CreateError(e.Message + " ------" + e.StackTrace));
                    rs.Add(irs);
                }
            }
            return(Ok(new ResponseModel(rs)));
        }