예제 #1
0
        public List <Cabinet> ToEntities()
        {
            var cabinets = new List <Cabinet>();

            for (int i = 0; i < CSV.Count; i++)
            {
                if (CSV[i].Count() != ColumnCount)
                {
                    throw new EntityParsingException("Invalid column count", i);
                }
                string name     = CSV[i][0];
                string typeName = CSV[i][1];
                string address  = CSV[i][2];
                string phone    = CSV[i][3];
                //check length
                if (name.Length > NameLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(name), name, i);
                }
                if (typeName.Length > typeNameLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(typeName), typeName, i);
                }
                if (address.Length > AddressLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(address), address, i);
                }
                if (phone.Length > PhoneLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(phone), phone, i);
                }
                //get id
                int?typeId;
                using (var context = new InventoryDbEntities())
                {
                    if (!IdTranslater.GetCabinetTypeId(typeName, out typeId, context))
                    {
                        throw new EntityParsingException("Name doesnt exist", "CabinetType", typeName, i);
                    }
                }
                var cabinet = new Cabinet()
                {
                    CabinetName   = name,
                    CabinetTypeId = typeId ?? -1,
                    Address       = address,
                    Phone         = phone
                };
                cabinets.Add(cabinet);
            }
            return(cabinets);
        }
예제 #2
0
        public List <TransactionPermission> ToEntities()
        {
            var entities = new List <TransactionPermission>();

            for (int i = 0; i < CSV.Count; i++)
            {
                string pType       = CSV[i][0];
                string userName    = CSV[i][1];
                string cabinetType = CSV[i][2];
                string note        = CSV[i][3];
                if (note.Length > NoteLength)
                {
                    throw new EntityParsingException("Invalid length", nameof(note), note, i);
                }

                int cId, userId;

                int?id;
                using (var context = new InventoryDbEntities())
                {
                    //to cabinet id
                    if (!IdTranslater.GetCabinetTypeId(cabinetType, out id, context))
                    {
                        throw new EntityParsingException("Name doesnt exist", "CabinetType", cabinetType, i);
                    }
                    cId = id ?? -1;
                    //username
                    if (!IdTranslater.GetUserId(userName, out id, context))
                    {
                        throw new EntityParsingException("Name doesnt exist", "Username", userName, i);
                    }
                    userId = id ?? -1;
                }

                var per = new TransactionPermission()
                {
                    PermissionTypeName = pType,
                    CabinetTypeId      = cId,
                    UserId             = userId,
                    Note = note
                };
                entities.Add(per);
            }
            return(entities);
        }